Professional Documents
Culture Documents
OOP Is Really Nice Structure
OOP Is Really Nice Structure
Attributes Methods
Analogy:
ATM machine can only update accounts of
one person when an authorized transaction is
made
Abstraction
Focus only on the important facts about the
problem at hand
To design, produce, and describe so that it
can be easily used without knowing the
details of how it works.
Analogy:
When you drive a car, you don’t have to
know how the gasoline and air are mixed and
ignited.
Instead you only have to know how to use
the controls.
Polymorphism
The same word or phrase can mean
different things in different contexts
Analogy:
In English, bank can mean side of a river or a
place to put money
Inheritance
Inheritance—a way of organizing classes
Term comes from inheritance of traits like
eye color, hair color, and so on.
Classes with properties in common can be
grouped so that their common properties
are only defined once.
Superclass – inherit its attributes &
methods to the subclass(es).
Subclass – can inherit all its superclass
attributes & methods besides having its
own unique attributes & methods.
Analogy?
Object Oriented
Languages
Five Rules
Everything is an object.
A program is a set of objects telling each
other what to do by sending messages.
Each object has its own memory (made up of
other objects).
Every object has a type.
All objects of a specific type can receive the
same messages.
All object oriented languages generally
follow these rules.
Object Oriented
Languages
Pure Object Oriented Languages:
Java
C#
JavaScript
Eiffel
Hybrid Languages
C++
Objective-C
Object-Pascal (Delphi)
Object Oriented Design
How to identify a class?
First identify its objects.
We’ll use the example of a car
Then identify what properties these object
have in common
Engine, color, seats, body, wheels etc.
These will be our attributes
Now identify the common actions that the
objects can perform
Accelerate, brake, ignition, switching off, turn
etc.
These will be the functions/methods of the
class.
Now, write the class.
Classes: A simple example
(Car)
class car
{
public string color{set;get;}
public void MyColor()
{
Console.WriteLine("My color is “+color);
}
} //end class
*do not copy and run this code, use the text file
provided on LMS instead
Usage
Now, to use this class in Main()
class Program
{
static void Main(string[] args)
{
car c1=new car();
c1.color="red";
c1.MyColor();
Console.ReadKey();
}
}