Presentation is loading. Please wait.

Presentation is loading. Please wait.

OBJECT ORIENTED CONCEPT

Similar presentations


Presentation on theme: "OBJECT ORIENTED CONCEPT"— Presentation transcript:

1 OBJECT ORIENTED CONCEPT
Chapter 3

2 Relationships Between Classes
When more than one class is used in a program, there can be three main types of relationships between objects from two or more of the classes. The simplest relationship is between two classes that are independent of each other but one class might use the services the other provides (Association) A class may be made up of other classes, or contain other classes that are part of itself (Aggregation / Composition) A class may inherit all the attributes and methods of a parent class, but is given a unique name as well as its own additional attributes and methods (Inheritance – generalization / specialization)

3 Association An association between two classes is required when the classes need to interact or communicate for the program to achieve its purpose Just as instances of classes are called objects, instances of associations are called links. In a class diagram, a small arrow indicates the direction to read the description of the association, although association allows communication in both directions. PERSON COMPANY WorksFor 

4 Multiplicity A flight attendant is serving many on board passengers
Indicates the number of objects that are associated with one particular class. Either one-to-one or one-to-many. For instance: A flight attendant is serving many on board passengers

5 Aggregation and Composition
A special type of relationship when a class consists of a number of component classes. These are whole-part associations: one class is the whole that is made up of the parts For example: Airport is a whole made up of parts including terminal, car park, air traffic control tower, etc

6 Aggregation and Composition
In an aggregation, it is not necessarily the case that each component belongs to one whole. For example, in a home entertainment system, a remote control may be a component of a television, and the same remote control could be a component of the videocassette recorder. Composition is a strict form of aggregation in which the part’s existence is dependent on the entirety. If the entirety is deleted, so are the instances. For example, consider that in a game of electronic chess the playing area is made up of classes ‘square’ and ‘board’. Each square is part of exactly one board. It would not be sensible to copy or delete the ‘board’ object without copying or deleting the ‘square’ objects.

7 Inheritance One of the most powerful attributes of OOP is it allows the developer to define relationship between classes that facilitate not only code reuse, but also organizing classes and factoring in commonalities of various classes. Inheritance allows a class to inherit the attributes and methods of another class which allows the creation of brand new classes by abstracting out common attributes and behaviors

8 Inheritance Sometimes, one class shares features with another class, but has enough differences to deserve its own identity The first class then becomes a kind of or type of the second class The top-level class, also called the parent class or superclass, has shared attributes and operations, and the child classes or subclasses, inherit these, adding their own attribute and operations to make them distinct


Download ppt "OBJECT ORIENTED CONCEPT"

Similar presentations


Ads by Google