Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object-Oriented Design Justin Callanan CS 597. Object-Oriented Basics ● Data is stored and processed in “objects” ● Objects represent generalized real.

Similar presentations


Presentation on theme: "Object-Oriented Design Justin Callanan CS 597. Object-Oriented Basics ● Data is stored and processed in “objects” ● Objects represent generalized real."— Presentation transcript:

1 Object-Oriented Design Justin Callanan CS 597

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


Download ppt "Object-Oriented Design Justin Callanan CS 597. Object-Oriented Basics ● Data is stored and processed in “objects” ● Objects represent generalized real."

Similar presentations


Ads by Google