|Lesson 7|| Pattern scope|
|Objective||Distinguish between Class and Object Patterns|
Distinguish between Class and Object Patterns
Patterns may be further divided according to their scope.
There are two pattern scopes:
Object patterns, the more common of the two, specify the relationships between objects.
In general, the purpose of an object pattern is to allow the instances of different classes to be used in the same place in a pattern.
Object patterns avoid fixing the class that accomplishes a given task at compile time.
Instead the actual class of the object can be chosen at runtime. Object patterns mostly use object composition
to establish relationships between objects.
Class patterns specify the relationship between classes and their subclasses.
Thus, class patterns tend to use inheritance to establish relationships.
Unlike object patterns and object relationships, class patterns generally fix the relationship at compile time.
They are less flexible and dynamic and less suited to polymorphic approaches.
Object patterns deal with object relationships, which can be changed at run-time and are more dynamic.
Almost all patterns use inheritance to some extent. So the only patterns labeled class patterns are those that focus on class relationships.
Note that most patterns are in the Object scope.
Class patterns deal with relationships between classes and their subclasses.
These relationships are established through inheritance, so they are static fixed at compile-time. Object patterns deal with object relationships, which can be changed at run-time and are more dynamic.
Class scope is defined at design time and is built in the structure and relationship of classes where as object scope is defined at runtime and is based on the relationship of objects.