4 types of methods to instantiate a new object

1) constructor — invoked directly by client methods
2) factory
3) special instance[1] methods to return a new object of its own class. Could be public or private.
4) singleton’s getInstance(). Static

Example of (3): shortcut constructor method.

#1 key question: How do you control access to these methods?
3) you need to get an instance of this class before calling this method. Get a chicken, then an egg.
1) no control
4) no control due to staticity
2) a static factory method offers limited control.

[1] static? less common.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s