Documente Academic
Documente Profesional
Documente Cultură
addInterest() addInterest()
public abstract class Account{
private long current_amount; public class Checkingsaccount
private String accountnr; extends Account {
private double interest_rate = 0.01;
public void deposit(long amount){
current_amount+=amount; public void addInterest(){
} deposit(getAmount()*interest_rate/2);
public void withdraw(long amount){ }
current_amount-=amount; }
}
public void setAccountnr(String anr){ public class Savingsaccount
accountnr=anr; extends Account {
} private double interest_rate = 0.0425;
public String getAccountnr(){
return accountnr; public void addInterest(){
} deposit(getAmount()*interest_rate);
public double getAmount(){ }
return current_amount; }
}
public abstract void addInterest();
}
public class Bank{
private Vector accountslist;
mybank.addInterest_all_accounts();
<<Abstract>>
} Account
} current_amount : double
Bank
accountnr : String
account slist : Vector
deposit()
addAccount ()
n withdraw()
delAccount()
setAcountnr()
addInterest_all_account s()
getAccountnr()
getAmount()
<<Abstract>> addInterest()
addInterest() addInterest()
Main
Main Points
Points
1. With polymorphism, objects of a
particular type can take many different
forms, giving us great power and
flexibility. The Unified Field is the source
of all different forms in the relative
creation.
Why do we want polymorphism?
•All systems change during their life cycle, but when a single
change results in a cascade of changes, the program becomes fragile
and unpredictable. When requirements change, you implement these
changes by adding new code, not by changing old code that already
works.
<<Abstract>>
addInterest() addInterest()
General technique:
•Abstract out the changing from the unchanging
•Put the unchanging in an abstract base class
•Encapsulate the changing aspect and place it in the subclass
Unchanging
+
Changing
unchanging
Changing 1 Changing 2
Main
Main Points
Points
2. The general technique used to apply the
strategy pattern is to abstract out the changing
from the unchanging, put the unchanging in an
abstract base class and encapsulate the
changing aspect in the subclass. Living a
successful life in the always changing relative
is possible through transcending to the most
abstract field, the never changing Unified Field
of all the Laws of Nature.
CONNECTING THE PARTS
OF KNOWLEDGE WITH THE
WHOLENESS OF
KNOWLEDGE
1. When requirements change, you should
implement these changes by adding new
code, not by changing old code that already
works.
2. The concept of variation-oriented
design underlies many OO principles.
One separates changing from non-
changing aspects of a class, and
delegates the responsibility for the
changing aspects to a class that can be
extended through polymorphism.
3. Transcendental Consciousness is the non-
changing field of all possibilities.