1 / 27

Object-Oriented Principals

www.espirity.com. Object-Oriented Principals. Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com). Additional Contributors. None as of Septembe, 2004. Module Overview. Object-Oriented Principals. Module Road Map. Object-Oriented Principals Objects

mvermillion
Download Presentation

Object-Oriented Principals

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. www.espirity.com Object-Oriented Principals Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

  2. Additional Contributors • None as of Septembe, 2004

  3. Module Overview Object-Oriented Principals

  4. Module Road Map • Object-Oriented Principals • Objects • Classes, instances, fields and methods • Encapsulation • Polymorphism • Inheritance • Dynamic binding

  5. What is Object-Oriented Technology? • It is a technology that allows modeling of software as the real world • This is achieved through objects and interactions between them • It is a way of thinking of software as reusable components • Every object is a component on its own and could be reused in different context

  6. Why Use Object-Oriented Systems? • Benefits of Object-Oriented systems: • Greater flexibility • Reusability of objects • Higher quality control • Lower maintenance

  7. Developing Object-Oriented Software • Software is modeled by objects • Software objects represent real-world objects • Each object contains: • State, i.e., data • Behavior, i.e., methods/functions

  8. Object-Oriented Software • Developing object-oriented software is identifying: • Objects • Characteristics of individual objects • Relationships between objects • Objects interact by sending messages to each other • Interacting objects make an object-oriented system

  9. Objects and Loose Coupling • Changing an object’s data does not lead to changes in an object’s external behavior • An object’s external interface stays the same • Promotes loose coupling between objects object2 object1 state state behavior behavior object3 state behavior

  10. Objects • Every object has: • State • Behavior • State represents data - what an object knows, or what an object contains • Behavior represents what an object can do

  11. Object State and Behavior • Person object • State: age, name, children • Behavior: addChild, getAge, setAge aPerson state age name children behavior getAge setAge addChild …

  12. Interactions between Objects • Object interact by sending messages to each other • Objects and interactions between them make up an object-oriented system aBroker: aPolicyFactory: aPerson: createPolicy aPolicy aPolicy: new(“Joe Smith”, “35 years”) aPerson setOwner(aPerson) …

  13. Messages • There are two major terms in messaging: • Message sender • Message receiver • Messages may have arguments aBroker: aPerson: receiver sender getAge() message

  14. Methods • Method is concrete implementation of a message • When message is sent to a receiver: • Method is found by type of the receiver object and method signature • Method code is executed • Method represents an object’s response to a message

  15. Method Signature • Method signature is unique identifier of the method • It is used to distinguish methods with same name and same number of parameters • It consists of: • Method name • Parameter name • Parameter type

  16. Object’s Public Protocol • Public protocol is set of messages that can be sent to an object • It does not include messages that an object can send to itself • These are private aPerson age name children getAge setAge addChild … public protocol

  17. Fields • Fields represent characteristics of an object • Fields are also known as attributes, or instance variables aPerson age name children fields getAge setAge addChild …

  18. Object-Oriented Principal: Encapsulation • Objects hide implementation of the messages behind their public protocols • Object’s internal implementation is accessed by that object only • Encapsulation is also known as implementation hiding aBroker: aPerson: getName() Joe Smith getAge() 35

  19. Classes • Classes are: • Factories for creating objects • Template for the same kind of objects that describes their state and behavior • Code repository for objects • Classes define objects (by defining their state and behavior) and their type Person age name children address getAge setAge addChild …

  20. Instances • Every object is an instance of some class • All instances of same class have the same protocol • They have same fields and same methods that are defined by the class class Person John Smith age name children address getAge setAge addChild … Dad Smith class 35 John Smith Jimmy, Chloe 60 Dad Smith John, Tom

  21. Object-Oriented Principal: Inheritance • Some classes may share commonalities • For example HomePolicy, AutoPolicy, LifePolicy classes may all have same state and behavior • Instead of repeating commonalities in each class, we can abstract them in a common place • These commonalities can be stored in a super class • Each subclass inherits state and behavior from its superclass

  22. Specialization and Generalization Policy client premium policyNumber getClient setClient … specialization generalization HomePolicy AutoPolicy LifePolicy house auto getHouse setHouse getAuto setAuto

  23. Why Inheritance? • Inheritance represents real-world modeling • Some objects are special cases of other objects • Inheritance promotes reuse and extensibility • Same data and behavior is shared among objects of different types (different class) • New data and new behavior that is common for those objects is easier to add

  24. Object-Oriented Principal: Polymorphism • Polymorphism • different objects respond to the same message in different ways • For example when asked to talk a dog barks, and a cat meows • It is often supported by method overriding • Overriding means that subclass may implement the same method as superclass, but with different code • toString() method in the Object class is an example of often overridden method

  25. Overriding Example • Consider Animal class: • Dog and Cat as subclasses • All Animal objects should know how to talk Animal talk() aCat.talk(); aDog.talk(); meows barks Cat Dog talk() talk()

  26. Dynamic Binding • Dynamic binding represents runtime method binding • It is runtime binding of method invoked in the message to the method that implements that message • For example: anAnimal.talk(); aDog aCat … … talk talk

  27. Labs! Lab: Object-Oriented Concept

More Related