Implement behavior with abstract state pattern

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m
m
Line 1: Line 1:
 +
This axiom is contained in [[PLoP 1995|Pattern Languages of Program Design]] and republished in [[Ken Auer 1995]].
 +
 
Defining the behaviour of a class without defining any of the data structure makes your class very flexible.  By delaying the specification of implementation details we make class hierarchies that are more extensible.  This allows us to follow the [[Once and only once]] principle, and allows subclasses to adapt to changing space and efficiency requirements.
 
Defining the behaviour of a class without defining any of the data structure makes your class very flexible.  By delaying the specification of implementation details we make class hierarchies that are more extensible.  This allows us to follow the [[Once and only once]] principle, and allows subclasses to adapt to changing space and efficiency requirements.
  
Line 6: Line 8:
  
 
== See also ==
 
== See also ==
* [[Ken Auer 1995]]
 
 
* [[Avoid concrete base classes]]
 
* [[Avoid concrete base classes]]
 +
* [[Ken Auer]]

Revision as of 06:52, 18 October 2010

This axiom is contained in Pattern Languages of Program Design and republished in Ken Auer 1995.

Defining the behaviour of a class without defining any of the data structure makes your class very flexible. By delaying the specification of implementation details we make class hierarchies that are more extensible. This allows us to follow the Once and only once principle, and allows subclasses to adapt to changing space and efficiency requirements.

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 makes your class very flexible to accommodate new special cases and variations.

See also

Personal tools