ObjectOrientation - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

ObjectOrientation

Description:

the basic unit of object orientation ... Car gas and brake pedals. I need air to breathe. Insert card, enter PIN, get money. 2-9 ... – PowerPoint PPT presentation

Number of Views:14
Avg rating:3.0/5.0
Slides: 17
Provided by: rickmercer
Category:

less

Transcript and Presenter's Notes

Title: ObjectOrientation


1
Object-Orientation
2
Outline
  • A non-language overview of object orientation

3
Object Oriented Programming
  • Object Orientation A problem solving technique
    to develop software systems
  • Objects
  • the basic unit of object orientation
  • an entity with attributes (values), behavior
    (methods), and identity (a way to find it)
  • may thing can be modeled as software
  • temperature sensor, employee, color, button,
    string, socket for networking, number, Connect-4
    Strategy

4
Objects
  • Objects
  • Have attributes set of stored values
  • Have responsibilities provided services
  • Provide access to the state such as whether a
    sensor is on or how many elements are in a list
  • Provide behavior such as reporting a temperature
    is too high or returning a reference to an object
    in a collection

5
OO Programs
  • Object oriented programs
  • have a collection of different types of objects,
    each with their own set of responsibilities
  • consist of many objects of the same type (5
    buttons, 1 million transactions)
  • A collection of objects of the same type are
    instances of the same class

6
Classes
  • Classes
  • A description of the attributes and behaviors of
    a set of objects
  • an object is an instance of a class all
    instances of a class have the same behavior (but
    different values)
  • Consider a system to monitor sensors in a factory
  • Will probably have a class named Sensor
  • The class defines location, ID, and services such
    as notifying of certain conditions as they occur

7
Object-oriented systems
  • Characteristics of object-oriented systems
  • Abstraction
  • Classes encapsulate state and behavior
  • Communication done via messages
  • Objects have a lifetime
  • Polymorphism via interfaces
  • Polymorphism via inheritance
  • Class hierarchies

8
Abstraction
  • Abstraction
  • A model of a real world object (e.g. a list) or a
    concept (e.g. a CardPlayerStrategy)
  • A simplified model of complex processing (sort
    the list, make a card playing decision)
  • A way to deal with the complexities of life
  • Car gas and brake pedals
  • I need air to breathe
  • Insert card, enter PIN, get money

9
Encapsulation
  • Encapsulation means
  • The state and behavior of objects are hidden from
    other parts of the system
  • Behaviors are invoked with well-defined messages
  • Encapsulation is made available via the class
    programming language construct
  • Behavior via methods
  • Attributes via instance variables

10
Communication via messages
  • Objects communicate with each other via messages
  • Messages consist of
  • the receiver (the object reference to which the
    message is sent)
  • a message name
  • arguments (optional)

11
Messages
  • Messages
  • can be sent as a normal part of the program
  • may originate from the operating system interface
    (mouse movement, button click)
  • may originate from the language runtime system
    (garbage collector reclaims memory)
  • Flow of messages is not always linear
  • may have users interacting with program to
    determine what the program will do next

12
Object lifetime
  • Some objects live only when the program runs
  • Other objects live only during a message objects
    constructed by a method
  • Other object persist between program runs
  • Serialize and write to disk

13
Object lifetime
  • Objects are created at runtime via a constructor
    (instantiation)
  • the constructor initializes state, allocates
    memory from the OS, and returns a reference to
    the object
  • Reference a way to find the object and its type
  • Objects can also be
  • Sent over the network
  • Read from and written to a disk

14
Object Lifetime
  • Objects have state and behavior
  • Objects have their own identity
  • can be distinguished from other objects
  • Java uses references to keep track of objects
  • A reference
  • has a way to locate the object
  • knows the object's type
  • it's more than an address, but it's not an address

15
Objects can Disappear
  • Objects are destroyed when no longer needed
  • When a method that constructs a local object
    finishes, the reference disappears
  • C code can explicitly destroy objects
  • Java uses a garbage collector to reclaim memory
    used by objects when there are 0 references to it

16
Summary
  • This has been an overview of object orientation
  • Object Oriented Programming and Design is also
    about these upcoming topics
  • Polymorphism
  • Inheritance
  • Design Heuristics
  • Design Patterns
  • Writing good code
Write a Comment
User Comments (0)
About PowerShow.com