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.

Blog at WordPress.com.

Up ↑