b) class C2 (Derived) is a subclass of class C1 when C2 extends the behavior of C1 (Base).
c) One big advantage of object-oriented programming is the ability to extend the behavior of an existing class while reusing the code written for the original class.
d) When a class is extended, the new class inherits all the fields (data and methods) of the class being extended.
This implies an "is a" relationship.
One class is derived from another, the base class.
Generalization is implemented as inheritance in C++.
The derived class has more specialization.
It may either override the methods of the base, or add new methods.
This implies a "has a" relationship.
One class is constructed from other classes, that is, it contains objects of any component classes.
For example, a car class would contain objects such as tires, doors, engine, and seats.
Two or more classes interact in some manner.
They may extract information from each other, or update each other in some way.
As an example,
a car class may need to interact with a road class, or
if you live near any metropolitan area,
the car class may need to pay a toll collector class.
o Generalization is the relationship between a class and one or more redefine versions of it.
o The class being redefined is called the super class and each redefine versions is called a subclass.
o Generalization is also called the “is-a” relationship because each instance of a subclass is an instance of the super class as well.
o The notation for generalization is a triangle connecting a super class to its subclasses.
o The term generalization is used to specify the classification relationship between a general element and a more specific element.
o In fact, the term 'generalization' specifies a viewpoint focused on a classification hierarchy.
o For example, a Shape is a more general concept than a Circle, a Rectangle, or a Triangle.
o Conversely, a Circle is a more specialized concept than an Shape.
o The more specific element may contain information that is particular to it, as long as it remains completely consistent with the description of the more general element.
o An association is a simple structural connection between classes.
o Association establishes relationship between two classes through their objects.
The relationship can be one-to-one, one-to-many, many-to-one and many-to-many.
o It also represents a relationship between two or more objects where all objects have their own lifecycle and there is no owner.
o The name of an association specifies the nature of relationship between objects. This is represented by a solid line (Fig-1)
o An association is assumed to be bidirectional, which means that you can navigate from either class to the other one.
However, you can specify that navigation can only occur from one class to another by using a feathered arrow, as shown in (Fig-2).
o Ex. Relationship between Teacher and Student.
Multiple students can associate with a single teacher and a single student can associate with multiple teachers. But there is no ownership between the objects and both have their own lifecycle.
Both can be created and deleted independently (Fig-3).
o When modeling, classes associate with one another, the association itself specifies a lot of information about the relationship. When such is the case, you may model the association as an 'association class' -- literally specifying that the association has class-like properties, such as attributes, operations, and other associations.
o In the UML Class diagram, the association class is shown as a class symbol attached to the association path by a dashed line. Logically, the association class and the association represent the same underlying model element, which has a single name; however, they are graphically distinct. The name may be placed on the path, in the class symbol, or on both.
o For example, you are building an application for Human Resources. In your application you want to specify that a class Person may have a job with the class Company. A person is paid a salary, and so you could model salary as an attribute of the class Person. But what if the person has more than one job (different companies), or even more than one job at your company (they might have a 9-5 job but also work freelance for another department). For a number of reasons, it makes sense to make the association contain job information such as salary (Fig-4).
• An association can contain roles, which are the faces that classes present to other classes.
As shown in Figure, roles generally appear in pairs (Fig-5).
One-to-One denotes a very narrow association.
Each association in the class diagram corresponds to asset of links in the instance diagram like each class corresponds to set of objects.
Examples
• Each country has a capital city. Has capital is the name of the association.
• One employee belongs to one organization.
• One dog belongs to one family.
• One person has one passport.
• A car model is made by one company.
• A house building prototype belongs to one company.
• A book is published by one company.
• A software program is made by one organization.
• An apple comes from one tree.
• Santa Claus is associated with one holiday.
• A person has one driver's license.
• The brakes on the car have one purpose.
• Each car-id has a car-driver