Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Describe something that you use in your day-to-day activities that could be d

ID: 3640699 • Letter: 1

Question

1. Describe something that you use in your day-to-day activities that could be described using object composition. Make sure you first describe the class that will contain the composite objects and then explain how the composite objects relate to the class that contains them.

2. Provide a simple class definition and then provide the syntax and the rationale for declaring an array of objects of the class. Also explain the dimension of the array and why you chose that number of elements for the object array.

Explanation / Answer

1. A very simple composition, taken from the real life would be a car object. It would be composed of many subsystems, including the engine, braking system etc. For a simple car interaction one would start the engine, initiate speedometer etc. All the composite objects are part of the main class (as aggregation) and do not exist on their own. 2. Suppose we have a class called Worker: public class Worker(){ public void setAction(Action a){ ... } public void doWork(){ ... } } This is a bit like a thread which you can reassign an action to fulfill. We can now instantiate in a WorkerManager a fixed array of Workers, let's say 20, which we would allocate for incoming requests. Another simple example would be any HashMap in java, where T2 is a class.