“Pertaining to a technique or a programming language that supports objects, classes, and inheritance.”
ISO/IEC 2382-15
“OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things.”
A. Kay
Wichtig beim OO Design sind Prinzipien (Information Hiding, Modularisierung, late binding), nicht die Programmiersprache.
Nutzung der Funktionalität eines Objekts nur über wohldefinierte Schnittstellen.
public class ArrayList<E> extends AbstractList<E>
implements List<E>,
RandomAccess
interface Foo {
public void bar();
}
class FooImpl1 implements Foo {
public void bar() { System.out.println("in FooImpl1"); }
}
class FooImpl2 implements Foo {
public void bar() { System.out.println("in FooImpl2"); }
}
void doSomethingWithFoo(Foo foo) {
foo.bar();
}
if (condition)
doSomethingWithFoo(new FooImpl1())
else
doSomethingWithFoo(new FooImpl2())
Methodenaufruf = senden einer Nachricht
class BankAccount {
private FxConverter fx = new FxConverter();
private double balanceCHF;
void depositEur(double amount) {
double asCHF = b.convertEurToCHF(amount))
this.updateBalance(balanceCHF + asCHF)
}
void updateBalance(double newBalance) {
balanceInCHF = newBalance;
}
}
// somewhere in currentObject
someAccount.depositEUR(500);