Understanding Object-Oriented Programming Concepts
Object-oriented programming (OOP) is a powerful paradigm that helps in organizing and designing programs effectively. This summary covers key aspects such as designing a program, top-down structured design, the importance of OOD, defining objects, identity, state, behavior in OOP, and examples of states in objects.
Download Presentation
![](/assets/img/so-down.gif)
Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
E N D
Presentation Transcript
1 Chapter 10 Introduction to Objects and Classess
How can one design a program? 2 Top-down structured design: uses algorithmic decomposition where each module denotes a major step in some overall process Object-oriented design: divides the problem into a set of objects that interacts to solve the problem. Your program s properties and behaviors are modelled based upon real objects like cars, books, houses, etc.
Why OOD? 3 Software is complex (too many people is doing too many things the mess is inevitable ) One of the main goals in programming is to avoid the redundancy and objects can help to do this (inheritance) Objects can help increase modularity through data hiding (encapsulation)
OK, but what is object ? 4 An object is a thing, either tangible or intangible. An object-oriented program consists of many objects. An object is composed of identity, state (attributes, data, and their current values) and behavior (operations) .
Identity, State, Behavior 5 Identity is the property of an object that distinguishes it from all other objects. The failure to recognize the difference between the name of the object and the object itself is the source of many errors in object- oriented (OO) programming.
Identity, State, Behavior 6 The state of an object encompasses all of the (static) properties of the object plus the current (dynamic) values of each of these properties A property is an inherent or distinctive characteristic, trait, quality, or feature that contribute to making an object uniquely that object We will use the word attribute, or data member, to refer to the state of an object
Examples of State 7 Properties Elevators travel up or down Vending machines accept coins Clocks indicate the current time Values Current floor Number of coins deposited The number of minutes since the last hour
Identity, State, Behavior 8 Behavior is how an object acts and reacts, in terms of state changes and interactions with other objects. An operation is some action that one object performs upon another in order to elicit a reaction. We will use the word method to describe object behavior in java. Invoking a method causes the behavior to take place.
Classes 9 Classes are the definitions (or blueprints) used to create objects. I d say: descriptions of objects. To make acar the manufacturer must first have a design from which to build the first car. Then, once all the problems are worked out, the design is used to build all the cars of that model.
Objects 10 An object is an instance of a class. If we have a class definition called Car, then we can think of Audi, BMW, and Corvette as each being an instance (object) of the class Car, i.e., they are each a type of car.
Object example 11 Audi 6 BMW Z3 Corvette Car Car Car Notice that all objects are of the same type. All objects are cars!
Classes and Objects 12 An object is an instance of exactly one class!!! Corvette can not be an instance of a car class and an instance of a plane class at the same time. An instance of a class, an object, belongs to that particular class. A Corvette is a car Corvette belongs to the class Car.
Classes 13 Once a class is defined you can create as many instances of the class (objects from the class) as you would like. Once a blue print is completed for the 2003 Porsche 911, Porsche will use an assembly line to build as many instances of the 2003 Porsche 911 as they wish.
Class car and objects- graphically 14 Car This line shows an instance-of relationship. Audi 6 BMW Z3 Corvette Car Car Car
Defining a class 15 Properties are variables which describe the essential characteristics of an object. Properties of a car: color, model, make, how many doors, transmission type, direction of movement, etc. Behaviors are methods that describe how the object behaves and how the properties may be modified. Behavior of a car: braking, changing gears, opening doors, moving forwards or backwards, etc.
16 Classes A class is a collection of fields (data) and methods (procedure or function) that operate on that data. Circle centre radius circumference() area()
17 Adding Fields: Class Circle with fields Add fields public class Circle { public double x, y; // centre coordinate public double r; // radius of the circle } The fields (data) are also called the varaibles.
18 Data Abstraction Declare the Circle class, have created a new data type Data Abstraction Can define variables (objects) of that type: Circle aCircle; aCircle = new Circle(); OR Circle bCircle = new Circle();