Real Life Examples of OOPs Based Topics

Real life example of "Abstraction"

In General words, Abstraction is Just Hiding the complex things behind a particular Procedure to make the procedure look simple.
Example: Monitor ON/OFF::--The user doesn't need to know much about all the chips functioning that happens when Monitor is switched ON or OFF..All he needs to know is On Function ON-Monitor is On and on function OFF-Monitor is off...

Or Better Look for a car--Everyone Knows that There's a special Gear machine Which changes the gear, nobody bother to know what all functionality undergoes for a gear to change.. So, That's abstraction(avoiding unwanted implementations to prevent Complexity).
So,If a developer provides a good abstraction, users won't be tempted to peek at the object's internal mechanisms.
Abstraction is achieved by making class abstract having one or more methods abstract. Which is nothing but essential characteristic which should be implemented by the class extending it. e.g.when you inventing/designing a car you define a characteristics like car should have 4 doors, break, steering wheel etc… so anyone uses this design should include this characteristics. Implementation is not the head each of abstraction. It will just define characteristics which should be included.

Real life example of "Encapsulation"

Encapsulation is restricting a user to follow a particular procedure to access control of a particular process. It Just provides safety and ensures system robustness.
Example:We can consider The HR in a company as a person that works on the principle of Encapsulation.i.e. we cannot talk to other departments directly we need to communicate them through HR. This ensures security and better maintenance of company's records.

Together we can take example of a UNDER CONSTRUCTION BUILDING..where we can say that things like 'no. of managers' required,Types of Materials,No of workers etc as abstraction as they need to there in every Building Construction.
But, at the same time, Inclusion of every such field into a CONTRACTOR which acts as a mediator between the workers and the Building-Investor can be looked upon as Encapsulation. As, It hides all the above properties into one Entity.
Hence If you would have understood till now you can say that abstraction is just a subset of ENCAPSULATION.i.e.Every entity that performs abstraction is encapsulated internally but every thing that shows encapsulation need not be abstraction always.
e.g. .ToString() Method defined in almost every class is implementation of Abstraction because We don't the functionaltiy Within,all we care is that it changes almost everything to string.And as it assembles a s a unit,it is encapsulated too..But,The private members that we hide and access through Properties is an example of encapsulation only as it is done basically keeping data security in mindd..!!
Hope This answers your Question..!!

Real life example of "Polymorphism"

Polymorphism is one in many forms. That’s it. We can see lots of examples in real time. If you think about a Dog, A Dog is an Animal. A Dog can be a pet. So a Dog can be in
many forms. The Dog is Animal type and it can be another type of Pet. 
Apart from types, behaviors can also take part of Polymorphism. For Example, Animals can swim. A Dog can swim, A Monkey also can swim. Dog and Monkey has their own way of swimming. Here, the swimming behavior is in many forms. A monkey can walk with two legs and also with four legs. Here, walking behaviour is in many forms. These are the examples for polymorphism in real world.

Let’s see how Polymorphism works in Java. Polymorphism allows you define a Super type and have multiple subtype implementations. There Are Two Types of Polymorphism in Java. One is compile time Polymorphism and it is sometimes referred as static Polymorphism and the other one is Runtime Polymorphism and it is sometimes referred as dynamic Polymorphism
Real life example of "Class and Object"

Object Oriented programming is about creating programs using as building blocks, "things" that exists in the real world, these real world things are called objects, hence object oriented
For instance, if you're creating a Address Book program, you may define the following objects:
person, address, phone
Among many, many others. Those would be real life objects, and you describe your program in terms of these abstractions.
With that in mind you can start describing some concepts.
Class is used to define the characteristics an objects will have. A class is used only as a template, or a blueprint. For instance, for all the persons in your address book, you may say they all will have:
   - name
   - last name
   - phone number
   - address
An address may have:
    - street
    - number
    - city
    - zip code
    - country
And so on. As you can notice, a class me be defined in terms of other classes, for instance, in this context, a person has one address.
An Object is a particular instance of a given class. When you add an entry to your address book, you create an object and fill in the attributes.
 onePerson  ofType Person is ( 
     - name = "Oscar"
     - last name = "Reyes"
     - phone number = "56 58 11 11"
     - address = anAddress ofType Address (
                     - street = "Tecolotes"
                     - number = 32
                     - city   = "D.F."
                     - zip code = 23423
                     - country = "Mexico"
So, this object a class instance with data. Other entry in the address book are other objects with different data.
That shows the difference between them.

No comments:

Post a Comment