9_Objective-C Composite Objects

What is Class Clusters

A group of private concrete subclasses under a public abstract superclass.

Example of class clusters

In NSNumber we have many clusters of classes like char, int, bool and so on.

So what’s exactly composite object?

By embedding a private cluster object in an object of our own design, we create a composite object.

The count method of the NSArray class is an example

The intervening object’s implementation of a method it overrides can be as simple as:

- (unsigned)count 
     return [embeddedObject count];

In the above example, embedded object is actually of type NSArray.


In the above example, we can see that validating array’s one function would not allow adding null objects that will lead to crash in the normal scenario. But our validating array takes care of it. Similarly, each of the method in validating array adds validating processes apart from the normal sequence of operations.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: