1 / 14

Object Oriented Programming in Java

Object Oriented Programming in Java. Object Oriented Concepts. 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. State and Behavior.

Download Presentation

Object Oriented Programming in Java

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. Object Oriented Programming in Java Object Oriented Concepts Object Oriented Programming in Java (95-707) 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 Object Oriented Programming in Java (95-707) Object oriented Concepts

  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 Object Oriented Programming in Java (95-707) Object oriented Concepts

  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 Object Oriented Programming in Java (95-707) Object oriented Concepts

  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 Object Oriented Programming in Java (95-707) Object oriented Concepts

  6. What is a Message • Software objects communicate between each other by sending messages to each other. Object Oriented Programming in Java (95-707) Object oriented Concepts

  7. Parts of a Message • Destination • object name • Name of behavior to exercise • object method • How to modify behavior and state • parameters Object Oriented Programming in Java (95-707) Object oriented Concepts

  8. Why are messages so great? • Allows hiding of internal data structures • Allows hiding on internal process logic • Allows remote calls Object Oriented Programming in Java (95-707) Object oriented Concepts

  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? Object Oriented Programming in Java (95-707) Object oriented Concepts

  10. Differences between Object and Classes • Source of confusion because of several definitions • In general: • Objects are instances of their respective class Object Oriented Programming in Java (95-707) Object oriented Concepts

  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 Object Oriented Programming in Java (95-707) Object oriented Concepts

  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 Object Oriented Programming in Java (95-707) Object oriented Concepts

  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 Object Oriented Programming in Java (95-707) Object oriented Concepts

  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. Object Oriented Programming in Java (95-707) Object oriented Concepts

More Related