Вы находитесь на странице: 1из 18

OO Concepts: Objects and Classes

Atul Gupta

Real World Objects

Real World Objects





Have identity and are distinguishable


Share two characteristics



State
Behavior

Real World Objects




Vary in complexity





Brush
Desktop lamp
Desktop radio
Space shuttle

Real World Objects

Real World Objects




Some Object contains other Objects

Software Objects


Conceptually similar to real-world objects:




they too consist of state and related behavior

Software Object: Cycle


1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.

class Bicycle {
int cadence = 0;
int speed = 0;
int gear = 1;
void changeCadence(int newValue) {
cadence = newValue;
}
void changeGear(int newValue) {
gear = newValue;
}
void speedUp(int increment) {
speed = speed + increment;
}
void applyBrakes(int decrement) {
speed = speed - decrement;
}
void printStates() {
System.out.println("cadence:"+cadence+" speed:"+speed+" gear:"+gear);
}
}

Software Objects


Advantages






Abstraction
Encapsulation (Modularity)
Information-hiding
Code re-use
Pluggability and debugging ease

Essence of an Object


OO technology stresses what an object is, rather then


how it is used
Use of an object



Depends of the application


Changes during development

Objects evolve and gradually stabilize than the way they


are used, and hence software system built on them are
more stable in the long run

Object-Oriented Concepts









Objects
Classes
Interfaces
Inheritance
Attributes
Methods
Encapsulation
Information Hiding, or
Visibility









Instances
Delegation
Polymorphism
Dynamic Binding
Aggregation
Association
Message Passing, or
interactions
Genericity

Class Modeling

Objects




The most fundamental entity in an OO Program


Defined by class data type
Consists of




Identifier
values
Behavior

Classes


A class is a pattern, a blue print, or a template for a


category of structurally identical entities
Created entities are called objects or instances



Class is like instance factory


Static entity

A class has three components






Name
Attributes (also termed as variables, fields, or properties)
Methods (also termed as operations, features, behavior,
functions)

Class

Class and Objects


b1:BankAccount
0001011
$11500

BankAccount
accountNumber
balance

b2:BankAccount
0000012
$2000

getBalance()
b3:BankAccount
0000202
$25000

Object Relationships


Association






Aggregation
Composition

Inheritance
Dependency

Next Lecture - Association

Summary





Object is the most fundamental entity in an OO System


A class is a factory of creating objects
A class is a non primitive data type
Objects may have relationships (among the same type or
different types)

Вам также может понравиться