Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating an object that has all the properties of two other objects?

Consider a sports club situation. A club can have a Club manager and 1 or more Coaches (1 coach per team) So, here is an example of the Manager and Coach classes.

Class ClubManager
{
    public void RegisterMember()
    {
        // code for registering a member..
    }
}

Class Coach
{
    public void DeviceTeamFormation()
    {
        // code for making a team formation..
    }
}

My issue is, how can I have a Club manager who is also a Coach? because there are sports clubs with this situation.

Appreciate any and all help. Thanks guys.

like image 206
fred Avatar asked Feb 16 '10 19:02

fred


People also ask

How do you combine properties of two objects?

Example 2: Merge Property of Two Objects Using Spread Operator. In the above example, two objects are merged together using the spread operator ... . Note: In both the above examples, if the two objects have the same key, then the second object's key overwrites the first object's key.

How do you combine two values of objects?

If you want to merge the second object into the first object, instead of creating a new object, you can use Object. assign() . The Object. assign(target, source) function merges the source into the target.

What is an object explain some properties of an object?

An object is a collection of properties, and a property is an association between a name (or key) and a value. A property's value can be a function, in which case the property is known as a method. In addition to objects that are predefined in the browser, you can define your own objects.


1 Answers

No, you cannot do this with classes. Interfaces however get you in that direction.

On the other hand, you may want to add another level of indirection and separate the manager and coach roles from persons, so that you can assign each role to a person (which may also be the same person).

like image 116
Lucero Avatar answered Oct 24 '22 08:10

Lucero