Abstraction Inheritance Object
Oriented Programming
Abstraction
It allows
complex real world to be represented in simplified manner. Example color is abstracted
to RGB. By just making the combination of these three colors we can achieve any
color in world.It is a model of real world or concept.
When constructing objects in OOP applications, it is
important to incorporate this concept of abstraction. Theobjects include only
the information that is relevant
in the context of the application. If you were
building a shippingapplication, you would construct a product object with
attributes such as size and weight. The color of the item wouldbe extraneous
information and would be ignored. On the other hand, when constructing an
order-entry application,the color could be important and would be included as
an attribute of the product object.
Abstraction
Abstraction in Object Oriented
Programming
helps
to hide the irrelevant details of an object. Abstraction is separating
the functions and properties that logically can be separated to a separate
entity which the main type depends on.
Abstraction means working with something we know how
to use without knowing how it works internally. A good example is a television
set. We don’t need to know the inner workings of a TV, in order to use it. All
we need is a remote control with a small set of buttons (the interface of the
remote) and we will be able to watch TV.
Abstraction
refers to the act of representing essential features without including the
background details or explanations. Classes use the concept of abstraction and
are defined as a list of abstract attributes such as size, weight and cost, and
functions to operate on these attributes. They encapsulate all the essential
properties of the objects that are to be created. Since the classes use the
concept of data abstraction, they are known as Abstract Data Types (ADT).
Inheritance
Hierarchy is
used to define more specialized classes based on a preexisting generalized
class.Example we have VEHICLE class and we can inherit this class make more
specialized class likeCAR, which will add new attributes and use some existing
qualities of the parent class. Its showsmore of a parent-child relationship.
This kind of hierarchy is called inheritance.
Inheritance is one of the pillar of Object Oriented
Paradigm. It is form of software reusability where new class(sub class) are
created from already existing class (super class) which enhance the
functionalities while using some of the properties from super class.
For example, Vehicle is a super class and Car,
Plane, Motorcycle, Ship, etc are subclass of Vehicle. As you can see that sub
class provides more specific functionality and clear picture of an object than
super class.
When multiple
classes share some of the same operations and attributes, a base class can
encapsulate thecommonality. The child class then inherits from the base class.
This is represented in the class diagram by a solid linewith an open arrowhead
pointing to the base class.
For example, a CorporateCustomer class and a RetailCustomerclass
could inherit common attributes and operations from a base Customer class,
The purpose of inheritance is to create a base class
that encapsulates properties and methods that can be used byderived classes of
the same type. For example, you could create a base class Account. A GetBalance
method is definedin the Account class. You can then create two separate
classes: SavingsAccount and CheckingAccount. Because theSavingsAccount class
and the CheckingAccount class use the same logic to retrieve balance
information, they inheritthe GetBalance method from the base class Account.
This enables you to create one common code base that is easierto maintain and
manage.
Different kinds
of objects often have a certain amount in common with each other. Mountain
bikes, road bikes, and tandem bikes, for example, all share the characteristics
of bicycles (current speed, current pedal cadence, and current gear). Yet each
also defines additional features that make them different: tandem bicycles have
two seats and two sets of handlebars; road bikes have drop handlebars; some
mountain bikes have an additional chain ring, giving them a lower gear ratio.
Object-oriented
programming allows classes to inherit commonly used state and behavior from
other classes. In this example, Bicycle now becomes the superclass of
MountainBike, RoadBike, and TandemBike. In the Java programming language, each
class is allowed to have one direct superclass, and each superclass has the
potential for an unlimited number of subclasses:
Inheritance is the process of forming a new class
from an existing class or base class.
The base class is also known as parent class or
super class, the new class that is formed is called derived class.
Derived class is also known as a child class or sub
class. Inheritance helps in reducing the overall code size of the program,
which is an important concept in object-oriented programming.
It is classifieds into different types, they are
Single level inheritance
Multi-level inheritance
Hybrid inheritance
Hierarchical inheritance
No comments
Post a Comment