The topics discussed in this handout are considered the basics of object-oriented programming. Some of them are language-independent, others are Java-specific. These topics, except perhaps for the last two, are supposed to be covered by the prerequisite chain for this course. Relationships between classes
Subtyping vs. subclassing/inheritance
Class-interface continuum C# (items 22, 23)
Static vs. dynamic type (item 3)
Reference semantics vs. value semantics C# (item 6)
Equality vs. identity C# (items 6, 26)
Packages/Namespaces C#
Member access C#
Being a descendent of java.lang.Object/System.Object C# (items 5, 9, 10, 27)Implementing classes are usually required to provide the following methods:
Clone in the context of the Composite pattern C# (items 14, 27)In general, cloning allows you to make a copy of an object. The clone method in Java is similar to the copy constructor in C++, but it is an ordinary method, unlike the copy constructor. Once you have the original object and its clone, then you can modify each one independently. Cloning models the real-life situation where you build a prototype of something, say a car or a piece of furniture, and once you like it, you clone it as many times as you want. These things are composites, and the need to be cloned deeply (recursively). As another example, imagine a parking garage with a list of cars that have access to it. To build another garage to handle the growing demand, you can clone the garage and the access list. But the cars should not get cloned. That's because the garage is not composed of the cars. As we can see, the conceptual distinction between aggregation and composition has significant consequences for the implementation of the relationship. True, both relationships are represented as references in Java. However, composites usually require a deep clone (if cloning is supported): each parent is responsible for cloning its children. Note also that you don't need to clone at all if your objects are not mutable because you wouldn't be able to distinguish the original from the clone anyway. |