Date post: | 17-Jan-2017 |
Category: |
Software |
Upload: | nadeesha-thilakarathne |
View: | 198 times |
Download: | 0 times |
Object Oriented Programming – Nadeesha Thilakarathne
Blueprint of a Smart Phone
HTC
Microsoft
Samsung
Apple
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
Galaxy S6 edge
Lumia 535
Desire 820 LTE
Main Features of Object Oriented Programming
Encapsulation
Polymorphism
Inheritance
Abstraction
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).
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.
Encapsulation
Data
Methods
Change
Access
Encapsulated
get()/set()
Use get Method
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.
Inheritance
Inheritance
Multiple inheritance is not supported in java through class(possible with interfaces)
InheritancePhone
HTC phone Microsoft phone Samsung phone
Inheritance • Super Class
Inheritance • Sub Class 01
Inheritance • Sub Class 02
Inheritance • Sub Class 03
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.
PolymorphismAs a Phone
As a Camera
As a MP3 Player
Phone
Polymorphism
Polymorphism
Compile Time(Static) Run Time(Dynamic)
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.
Static Polymorphism(Static Binding)
Static Polymorphism(Static Binding)
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.
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.
Dynamic Polymorphism(Dynamic Binding)
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
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.
Abstract Class
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.
Inheriting the Abstract Class
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( විස්තාරණය )
References• http://www.umsl.edu/~sauterv/analysis/488_f01_papers/quillin.htm• http://www.codeproject.com/Articles/602141/Polymorphism-in-NET• http://www.sitepoint.com/quick-guide-to-polymorphism-in-java/• http://www.tutorialspoint.com/java/java_abstraction.htm• http://tutorials.jenkov.com/java/abstract-classes.html• http://
www.w3resource.com/java-tutorial/java-object-oriented-programming.php• http://www.javatpoint.com/java-tutorial
Your Valuable Feedback is
always welcome…. Nadeesha