1 / 10

Object-Oriented Design

Justin Callanan CS 597. Object-Oriented Design. Object-Oriented Basics . Data is stored and processed in “objects” Objects represent generalized real world things Objects have attributes and behaviors Attributes describe the object Behaviors change or act on attributes.

buehlert
Download Presentation

Object-Oriented Design

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. Justin Callanan CS 597 Object-Oriented Design

  2. Object-Oriented Basics • Data is stored and processed in “objects” • Objects represent generalized real world things • Objects have attributes and behaviors • Attributes describe the object • Behaviors change or act on attributes

  3. Using Objects as Representations • Objects typically correspond to real world entities • Examples: • Dog object, with: • An attribute for its breed • A behavior called “bark” • Cat object, with: • An attribute for its color • A behavior called “meow”

  4. Classes and Objects • Classes serve as the blueprint for objects • This blueprint is used to create instances • Each instance of an object has its own data • All data for an object is stored within it • Example: • Instance of the Cat object, with the color “grey” • Instance of the Cat object, with the color “orange”

  5. Generalizing and Specializing • Objects range from abstract to specific • Classes can be derived from one another • Derived classes are always more specific • Derived classes are called “subclasses” or “child classes” • Subclasses are derived from a “superclass,” or “parent class” • Example: • Animal superclass • Dog & Cat subclasses derived from Animal

  6. Inheritance • Subclasses “inherit” attributes and behaviors from superclasses • Subclasses can have additional attributes and behaviors • Inherited behaviors are identical unless “overridden” • Overriding behaviors replaces their internal logic • Example: • Animal superclass with attribute “weight” and behavior “speak” • Cat subclass with overridden “speak” behavior • Dog subclass with overridden “speak” behavior

  7. Polymorphism • Polymorphism is the ability to use subclasses in place of their superclass • Example: • A piece of code uses Animal’s “speak” behavior • The code is given a Cat or Dog object • The code runs, using Cat’s or Dog’s “speak” behavior

  8. Encapsulation • Classes contain all data associated with an object • Data is kept hidden from outside entities • Object data is retrieved through “accessor” behaviors (“getters”) • Object data is changed through “mutator” behaviors (“setters”) • Accessors and mutators can contain unique internal logic

  9. Abstraction • Abstract classes can be used as superclasses • Abstract classes cannot be used to create objects • They serve only as a consistent reference point • They can have incomplete implementations • Code can be written generically with abstract classes • Example: • Abstract Animal superclass • Non-abstract Cat and Dog subclasses (derived from Animal)

  10. Other important points • Objects can contain other objects • Objects can interact with one another • Not all object data is hidden • Behaviors can accept input, provide output, do both, or neither

More Related