OOPS
Class:
- Templates used for defining new types.
- describes all the attributes of objects,
as well as the methods that implement the behavior of member objects.
Objects:
- Instance of a class is called an Object
Characteristics of objects:
1. State:
The state of an
object encompasses the current values of all of its attributes. An attribute
could be static (whose value doesn’t change over period of time) or dynamic
(whose values change).
E.g. A car is
defined by: color, average, power, fuel type (static), speed, fuel level, gear
(dynamic)... Etc.
2. Behavior:
Behavior is how an
object acts or reacts, in terms of state changes and operations performed on
it.
E.g. A Windows
object, the operations performed on it can be open, close, maximize, move,
resize, and so on. Totality of operations performed on the window and the
consequent changes in the attributes define the behavior of the window.
3. Identity:
Identity is that
property of an object which distinguishes it from all other objects. E.g. Each
Student in the class identified by a unique roll number.
4. Responsibility:
The Responsibility
of an object is the role it serves within the system.
Example: Object –BANK ACCOUNT
Attributes
|
State
|
Behavior
|
Identity
|
Responsibility
|
|||||
Balance
|
Balance=1000
|
|
A/c No=10
|
Keeps a
track of a stores money with the facility of deposits and Withdraw.
|
|||||
Interest Rate
|
Rate=10%
|
||||||||
Account No
|
A/c No=10
|
1. Abstraction:
Abstraction refers
to the act of representing essential features without including background
details.
It facilitates the
easy conceptualization of real world objects into the software program.
Classes use the
concept of abstraction and are defined as a list of abstract attributes, and
functions to operate on these attributes.
2. Encapsulation:
The
property of being self-contained unit is called ‘Encapsulation’.
The wrapping up of
data and functions into a single unit (called class) called ‘Encapsulation’.
This
insulation of the data from direct access by the program is called
‘data hiding.’
Encapsulation
essentially deals with data hiding and providing the interface to the user of
the object.
Complexity of the
system is encapsulated from end user to improve usability using simple
interface.
3. Polymorphism
Ability
to take more than one form is called ‘polymorphism’. In other words, one
command may invoke different implementations for different objects.
For Example,
Consider the operation of addition, For two numbers. The operation will
generate a sum. If the operands are strings, then the operation would produce a
third string by concatenation.
Polymorphism
/\
/ \
/ \
CompileTime RunTime
/\ |
/ \ |
/ \ |
Function Operator Virtual functions
Overloading Overloading
4. Inheritance
It is a property of
class hierarchy whereby each derived class inherits attributes and methods of
its base class.
It
provides code reusability and extensibility.
It defines
relationship between classes and share common structure and behavior.
No comments:
Post a Comment