Implement behavior with abstract state pattern
(New page: Defining the behaviour of a class without defining any of the data structure leaves your class very flexible. By delaying the specification of implementation details but providing a class ...) |
m |
||
Line 4: | Line 4: | ||
When you are defining your base class implement all the functionality that the public interface requires. Every time you find that you require some data from the class define an abstract [[Getters and setters|accessor method]] instead of an instance variable. Later a class that extends your base class can fill in all the details of the data structure and the accessor methods. This also leaves your class very flexible to accommodate new special cases and variations. | When you are defining your base class implement all the functionality that the public interface requires. Every time you find that you require some data from the class define an abstract [[Getters and setters|accessor method]] instead of an instance variable. Later a class that extends your base class can fill in all the details of the data structure and the accessor methods. This also leaves your class very flexible to accommodate new special cases and variations. | ||
+ | |||
+ | == See also == | ||
+ | * [[Ken Auer 1995]] |
Revision as of 02:15, 3 August 2009
Defining the behaviour of a class without defining any of the data structure leaves your class very flexible. By delaying the specification of implementation details but providing a class interface that is already functional you manage to stick to the Once and only once principle and also create a class that allows subclasses to adapt to changing space and efficiency requirments.
What to do
When you are defining your base class implement all the functionality that the public interface requires. Every time you find that you require some data from the class define an abstract accessor method instead of an instance variable. Later a class that extends your base class can fill in all the details of the data structure and the accessor methods. This also leaves your class very flexible to accommodate new special cases and variations.