Containment is the replacement of inheritence,no no if inheritance isn’t the right choice,then the answer is containment, also known as aggregation. Rather than saying that an object is an example of another object, an instance of that other object will be contained inside the object. So,instead of having a class look like a string, the class will contain a string (or array, or hash table).
The default design choice should be containment, and you should switch to inheritance only if needed(i.e., if there really is an “is-a” relationship).
The default design choice should be containment, and you should switch to inheritance only if needed(i.e., if there really is an “is-a” relationship).