Object Oriented Programming in Java 95707 - PowerPoint PPT Presentation

About This Presentation
Title:

Object Oriented Programming in Java 95707

Description:

Write an OO program that simulates a furnace, a thermostat, and a user. ... First the thermostat gets the set point from the user. Then the thermostat get the ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 15
Provided by: alaink
Category:

less

Transcript and Presenter's Notes

Title: Object Oriented Programming in Java 95707


1
Object Oriented Programming in Java
  • Object Oriented Concepts

2
What is an Object?
  • An object is a software bundle of related
    variables and methods.
  • Software objects are often used to model
    real-world objects you find in everyday life

3
State and Behavior
  • The State of an object is represented by the
    values of its variables
  • The Behavior of an object is represented by its
    methods

4
Encapsulation
  • Not a new idea. Examples are
  • DLLs in Windows
  • Procedure in Pascal
  • Functions in C
  • Important because of the need to
  • keep system modular
  • promote information hiding

5
Controlling Access to Objects State and Behaviors
  • Java has a number of built-in mechanism to do so
    using simple keywords such as
  • private
  • public
  • protected

6
What is a Message
  • Software objects communicate between each other
    by sending messages to each other.

7
Parts of a Message
  • Destination
  • object name
  • Name of behavior to exercise
  • object method
  • How to modify behavior and state
  • parameters

8
Why are messages so great?
  • Allows hiding of internal data structures
  • Allows hiding on internal process logic
  • Allows remote calls

9
What is a Class?
  • A class is a blueprint or prototype that defines
    the variables and methods common to all objects
    of a certain kind
  • Different objects can have the same class
  • Cars, Vans, Trucks are all objects of the class
    automobile
  • Are automobiles different from vehicles?

10
Differences between Object and Classes
  • Source of confusion because of several
    definitions
  • In general
  • Objects are instances of their respective class

11
What are the possible relationships between
objects
  • Is-a relationship
  • implements the behavior of some type
  • Inheritance relationship
  • subclass of some other object
  • Is made of relationship
  • declares other objects

12
Inheritance
  • Key concept in OO programming
  • Very powerful
  • To be used very carefully
  • Java enforces a single inheritance model
  • can inherit State and Behavior from super class
  • can override or add to super class state and
    behavior

13
Interfaces
  • Very powerful
  • Difficult to understand where to use at first
  • To be used a lot
  • Allows to
  • capture similarities between classes without
    artificially forcing a relationship

14
Modeling Example
  • Write an OO program that simulates a furnace, a
    thermostat, and a user.
  • Example behaviors and states
  • First the thermostat gets the set point from the
    user. Then the thermostat get the current
    temperature from a thermometer.
  • Then the thermostat tests the current temperature
    against the set point. If the current
    temperature is above the set point, the
    thermostat does not to turn the furnace on (or
    turns it off if already on)
  • When the furnace is turned on it announces that
    it has been turned on.
Write a Comment
User Comments (0)
About PowerShow.com