120 likes | 131 Views
Learn about the principles of encapsulation and information hiding in object-oriented programming, class hierarchy, inheritance, polymorphism, associations, and aggregations.
E N D
Object basics (continued) Encapsulation & Information Hiding Class Hierarchy Inheritance Polymorphism Associations Aggregations Object Oriented Analysis and Design Agenda
An object is said to encapsulate the data & a program No object can operate directly on another object’s data Object’s internal format is insulated from other object’s Permissible operations Data Private Protocol Massages Public Protocol Object basics: Encapsulation & Information Hiding:
Very general encapsulation mechanisms are private, public & protected Public members may be accessed from anywhere Private members are accessible only from within a class Protected members can be accessed only from subclasses Object basics: Encapsulation & Information Hiding: Encapsulation & Information Hiding:
An important factor in achieving encapsulation is the design of different classes of objects that operate using common protocol Protocol is an interface to the object TV contains many complex components, but you do not need to know about them to use it Data abstraction is a benefit of the object oriented concepts that incorporates encapsulation & polymorphism Object basics: Encapsulation & Information Hiding:
Object basics: Class Hierarchy: • An object oriented system organize classes into a super class – subclass hierarchy • Different properties and behaviors are used as the basis for making distinction between super & subclasses • A subclass inherits all of the properties & methods defined in a super class • Eliminates duplication by allowing classes to share & reuse behaviors
Object basics: Inheritance: • A relationship between classes where one class is the parent of another class • It allows classes to share & reuse behavior & attributes • We can “build on what we already have” & “reuse what we already have”
Object basics: Multiple Inheritance: • OO systems permit a class to inherit from more than one superclass • This kind of inheritance is referred to as multiple inheritance • For example utility vehicle inherits from Car and Truck classes
Object basics: • Poly means “many” & morph means “form” • Same operation may behave differently on different objects • Draw message can be sent to many objects like triangle, circle or line & each object could act differently • Polymorphism is the main difference between a message and a subroutine call • It allows us write generic, reusable code more easily, because we can specify general instructions & delegate the implementation details to the object involved Polymorphism:
Object basics: Associations: • Represents relationship between objects • For example a pilot can fly planes. • Associations are Bidirectional • An important issue in association is cardinality
Request for printing PrintServer Item Object basics: Associations: Client server association: • A special form of association is a client-server relationship. • This relationship can be viewed as one-way interaction: one object (client) requests the service of another object (server).
Book Publication Author Category Object basics: Aggregations: • Aggregation is a form of association • Objects are composed of & may contain other objects • One object’s attributes can reference to other objects, where an attribute can be object itself • Example
Object basics: Aggregations: • Example