+ All Categories
Home > Software > Object oriented programming

Object oriented programming

Date post: 17-Jan-2017
Category:
Upload: nadeesha-thilakarathne
View: 198 times
Download: 0 times
Share this document with a friend
34
riented Programming – Nadeesha Thilak
Transcript
Page 1: Object oriented programming

Object Oriented Programming – Nadeesha Thilakarathne

Page 2: Object oriented programming

Blueprint of a Smart Phone

HTC

Microsoft

Samsung

Apple

Page 3: Object oriented programming

Operating System Model Price Battery Life

Sending SMS Voice Calling Video Calling Taking Pictures Listen to Music

Attributes of a Phone

Functions of a Mobile Phone

Page 4: Object oriented programming

Galaxy S6 edge

Lumia 535

Desire 820 LTE

Page 5: Object oriented programming

Main Features of Object Oriented Programming

Encapsulation

Polymorphism

Inheritance

Abstraction

Page 6: Object oriented programming

Encapsulation

A black box is a device, system or object which can be viewed in terms of its inputs and outputs (or transfer characteristics), without any knowledge of its internal workings. Its implementation is "opaque“(පාරාන්ධ) (black).

Page 7: Object oriented programming

Encapsulation • Providing access to an object only through its messages, while keeping

the details private is called encapsulation“.• Encapsulation is important because parts of software must

sometimes be changed or re-used.

Page 8: Object oriented programming

Encapsulation

Data

Methods

Change

Access

Encapsulated

get()/set()

Page 9: Object oriented programming

Use get Method

Page 10: Object oriented programming

Inheritance• Inheritance is useful way to reuse code when classes share an is-

a relationship.• More specifically, if two or more classes share common behaviors

because one is a more general type of the other.• This suggests that the more specific type can "inherit" those

behaviors from the more general type.

Page 11: Object oriented programming

Inheritance

Page 12: Object oriented programming

Inheritance

Multiple inheritance is not supported in java through class(possible with interfaces)

Page 13: Object oriented programming

InheritancePhone

HTC phone Microsoft phone Samsung phone

Page 14: Object oriented programming

Inheritance • Super Class

Page 15: Object oriented programming

Inheritance • Sub Class 01

Page 16: Object oriented programming

Inheritance • Sub Class 02

Page 17: Object oriented programming

Inheritance • Sub Class 03

Page 18: Object oriented programming

Polymorphism

One Name Many Forms

With polymorphism, the same method or property can perform different actions depending on the run-time type of the instance that invokes it.

Page 19: Object oriented programming

PolymorphismAs a Phone

As a Camera

As a MP3 Player

Phone

Page 20: Object oriented programming

Polymorphism

Polymorphism

Compile Time(Static) Run Time(Dynamic)

Page 21: Object oriented programming

Static Polymorphism(Static Binding)

• Compile time polymorphism/ Method overloading• Method overloading means there are several methods present in a

class having the • same name but • different types/order/number of parameters.

• The compiler does not consider return type when differentiating methods, so you cannot declare two methods with the same signature even if they have a different return type.

Page 22: Object oriented programming

Static Polymorphism(Static Binding)

Page 23: Object oriented programming

Static Polymorphism(Static Binding)

Page 24: Object oriented programming

Dynamic Polymorphism(Dynamic Binding)• Run-time polymorphism is achieved by method overriding.• Method overriding allows us to have methods in the base and

derived classes with the same name and the same parameters.

Page 25: Object oriented programming

Dynamic Polymorphism(Dynamic Binding)• By runtime polymorphism, we can point to any derived class from

the object of the base class at runtime that shows the ability of runtime binding.• Through the reference variable of a base class, the determination of

the method to be called is based on the object being referred to by reference variable.

Page 26: Object oriented programming

Dynamic Polymorphism(Dynamic Binding)

Page 27: Object oriented programming

Abstraction • Abstraction is a process of hiding the implementation details from the user.

• Only the functionality will be provided to the user. In other words user will have the information on what the object does instead of how it does it.

Abstract Class Abstract Method

Page 28: Object oriented programming

Abstract Class • Abstract classes may or may not contain abstract methods • But, if a class have at least one abstract method, then the class must be declared

abstract.• Abstract class cannot be instantiated.• To use an abstract class you have to inherit it from another class, provide

implementations to the abstract methods inside the class.• If you inherit an abstract class you have to provide implementations to all the

abstract methods in it.

Page 29: Object oriented programming

Abstract Class

Page 30: Object oriented programming

Abstract Methods• Abstract keyword is used to declare the method as abstract.• You have to place the abstract keyword before the method name in the method

declaration.• An abstract method contains a method signature, but no method body.• Instead of curly braces an abstract method will have a semicolon ( ; ) at the end.

Page 31: Object oriented programming

Inheriting the Abstract Class

Page 32: Object oriented programming

Conclusion• An object is an instance of a class.• Encapsulation provides the security that keeps data and methods safe from

inadvertent( න�ාසැලකිල්නලන් සිදු ව�) changes.• Inheritance is parent-child relationship of class which is mainly used for code

reusability.• Polymorphism definition is that Poly means many and morphos means forms.• Using abstraction one can simulate real world objects.• Abstraction provides advantage of code reuse• Abstraction enables program open for extension( විස්තාරණය )

Page 34: Object oriented programming

Your Valuable Feedback is

always welcome…. Nadeesha


Recommended