This document discusses key concepts in object-oriented programming including encapsulation, inheritance, polymorphism, and abstraction. Encapsulation involves restricting access to certain areas of a class and providing access through public methods. Inheritance allows classes to share behaviors through a parent-child relationship. Polymorphism enables one interface to have different implementations. Abstraction hides implementation details and exposes only functionality through abstract classes and interfaces.
3. 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
5. Main Features of
Object Oriented Programming
Encapsulation
Polymorphism
Inheritance
Abstraction
6. 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).
7. 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.
10. 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.
18. 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.
21. 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.
24. 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.
25. 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.
27. 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
28. 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.
30. 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.
32. 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(විස්තාරණය )