1 / 25

Object Basics: Encapsulation & Information Hiding

Learn the basics of object-oriented programming, including objects, classes, methods, and encapsulation. Understand the concept of information hiding and how it helps in creating better software.

dbock
Download Presentation

Object Basics: Encapsulation & Information Hiding

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Object basics Object Objects responds to messages Classes Meta-Class Agenda

  2. Object basics: Motivating factor behind OOAD: Make software development easier & more natural by raising the level of abstraction to the point where applications can be implemented Object: • It was first formally utilized in the simula language to simulate some aspect of reality • A real world entity, identifiable separate from its surroundings • A combination of data and logic that represents some real world entity • It is associated with • Properties • Procedures • Identity • persistence

  3. Describe the state of an object It refers to description rather than how they are represented in a particular programming language Example I am an Employee. I know my name, social security number and my address. Object basics: Object properties (Attributes):

  4. Example Object basics: Object properties (Attributes): I am a Car. I know my color, manufacturer, cost, owner and model.

  5. Methods or procedures define its behavior Behavior denotes the collection of methods that abstractly describes what an object is capable of doing Method encapsulate the behavior of an object, provide interface to the object The use of methods to exclusively access or update properties Object take responsibility for their own behavior. It simplifies application development & maintenance Object basics: Object procedures (Methods):

  6. I know how to Compute my payroll. Object basics: It does things Object procedures (Methods): • Example

  7. I know how to stop. Object basics: Object procedures (Methods): • Example

  8. Every object has its own unique & immutable identity It comes into being when the object is created & continue to represent that object from then on This identity never confused with another object, even if the original object has been deleted. It never reused The identity name never changes even if all the properties of the object change OID’s help to establish relationships/communication among objects OID’s help to implement object references during implementation Example : Employee Id, stud_Reg_Number Object basics: Object Identity (OID):

  9. Object have life time They are explicitly created & can exist for a period of time (usually the duration of the process in which they were created) An object can persist beyond application session, this characteristics is called object persistence A file or database provides longer lifeline The lifetime of an object can be explicitly terminated. After an object is deleted Object basics: Object persistence:

  10. Object basics: Objects responds to messages: • Messages essentially are non specific function calls • Objects respond to messages according to methods defined in its class • Different objects can respond to same message in different ways • Polymorphism is the main difference between a message and a subroutine call • Draw message can be sent to many objects like triangle, circle or line & each object could act differently

  11. Object basics: Objects responds to messages (con’t): • Message is the instruction & Method is the implementation • A message has a name just like method • An object understands a message when it can match the message to a method that has the same name as the message • Message says what to do & method says how to do something • Message so general, it can be used over & over again in many different contexts • Changes to method has no impact on messages & system

  12. Classes are used to distinguish one type of object from another Class is a set of objects that share a common structure & common behavior A single object is simply an instance of a class Every object of a given class has the same data format & responds to the same instructions Can create unlimited instances (except for singleton) Can use any of the predefined classes Object basics: Classes:

  13. Everything is an object. How about a class? Is a class an object? Yes, a class is an object! So, if it is an object, it must belong to a class. Indeed, class belongs to a class called a Meta-Class or a class' class. All classes are instances of a Meta-class Object basics: Meta Class (con’t):

  14. Meta-class used by the compiler. For example, the meta-classes handle messages to classes, such as constructors , "new“ and static member data Object basics: Meta Class:

  15. 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:

  16. 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:

  17. 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:

  18. 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

  19. 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”

  20. 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

  21. 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:

  22. Object basics: Associations: • Represents relationship between objects • For example a pilot can fly planes. • Associations are Bidirectional • An important issue in association is cardinality

  23. 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).

  24. 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

  25. Object basics: Aggregations: • Example

More Related