Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and the Unified Process, Second Edition
by Craig Larman
16.7. Creator
Assign class B the responsibility to create an instance of class A if one or more of the following is true:
B aggregates A objects.
B contains A objects.
B records instances of A objects.
B closely uses A objects.
B has the initializing data that will be passed to A when it is created (thus B is an Expert with respect to creating A).
Solution
B is a creator of A objects.
If more than one option applies, prefer a class B which aggregates or contains class A.
Who should be responsible for creating a new instance of some class?
Problem
The creation of objects is one of the most common activities in an object-oriented system. Consequently, it is useful to have a general principle for the assignment of creation responsibilities. Assigned ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access