Sei sulla pagina 1di 21

OOPS

Abstract Class
Abstractclassesdeclaredusingtheabstract keyword and
only represent as a base classes, no one can instantiate
(createobjects)theseclasses.
Abstractclassis
aclassthat
contain
complete
andabstract (incomplete) bothtypeofmemberanditcannot
beinstantiated.
Through abstract class we can provide behavior as well
as functionalitybothinthesametime.

Real Time Example of Abstract Class


Making a chess program and we're using 6 classes to
representthedifferentchesspieces(pawn, knight, bishop,
rook, queen, king).

Differentinmove
Common

inlocation,moved already, color.


In this case it would be good if all the classes could
inherit from another class containing those common
properties.

The solution in Chess Program is to use a Abstract class


publicabstract classChesspiece
{
PointLocation{get;set;}
boolHasMoved{get;set;}
ColorOwner{get;set;}
}
publicclassPawn:ChessPiece
{
//restofclasshere
}
publicclassRook:ChessPiece
{
//restofclasshere
}
publicclassPawn:ChessPiece
{
//restofclasshere
}
publicclassRook:ChessPiece
{
//restofclasshere
}
publicclassPawn:ChessPiece
{
//restofclasshere
}
publicclassRook:ChessPiece
{
//restofclasshere
}

Situation For Abstract Class


We define abstract classes when we define a template
thatneedstobefollowedbyallthederivedclasses.
Thisisusefultoavoid code duplicationinmanycases.
Abstract classes are also useful in the case of
modifications to the project.
Automatically all the inheriting classes will have the
samefunctionalitywithout disturbing the hierarchy.

Abstract Class In Quantum


LoanModification
PreparingPackageforsigning
PreparingPackageforpublishing
ValidatingtheBorrowerdetails
TohandleActioninTransactionmanagement

Interfaces
Interface is a type which contains only the signatures of
methods,delegatesorevents,ithasnoimplementation.
Implementation of the methods is done by the class that
whichimplementstheinterface.

An interface states what an object can do, but not


howitisdone.

Real Time Example of Interfaces

ConsiderweareworkingonMicrosoft Outlook project whereweneedtoadd,edit,save


contacts.
Sowecancreate interface withdeclarationofalladd,edit,savemethods.
Inherit interface ineverywhereinourprojectwhereweneedtoadd,edit,save.Nowwe
usesamenamedmethodforadd,edit,saveineverywhere.
Wecaninheritmorethanoneinterfacethatismajoradvantage.

Interfaces in Quantum
FrameworkWebInterfacesandNavigationinterfaces
Alertcontrol
BorrowerDetailsmanagement
ConditionManagement
Portfoliomanagement
Ordermanagement
Productandorderingmanagement
Investorsdetails
Documentmanagement

Abstraction
Abstractionismechanismtoshow only relevant data to
theuser.
It is process of identifying the relevant qualities and
behaviorsanobjectshouldpossess.
In other word represent the necessary feature without
representingtheback ground details.

Real Time Example of Abstraction


Whenever we buy a mobile phone, we see their
differenttypesoffunctionalities:
camera
mp3 player
calling function
recording function
multimedia

It is abstraction, because we are seeing only relevant


informationinsteadoftheirinternalengineering.

Encapsulation
Encapsulationistheprocessofhiding irrelevant data
fromtheuser.
Encapsulationistheprocessofhiding or securing data
fromoutsidefunctions.
The data is strictly binded with function members
declaredinthesameclass.

Real Time Example of Encapsulation


Wheneverwebuyamobile,wedontsee
howcircuitboardworks.
howdigitalsignalconvertsintoanalogsignal

These are the irrelevant information for the mobile user,


thatswhyitisencapsulatedinsideacabinet.

Polymorphism
Polymorphismsisnothingbutabilitytotakemorethanoneforms.
OneInterface,MultipleMethods(or)
OneName,ManyForms
ExampleofCompileTimePolymorphism:Method Overloading
ExampleofRunTimePolymorphism:Method Overriding
Method Overloading:Method with same name but with different arguments is
calledmethodoverloading.

Method Overriding:Methodoverridingoccurswhenchildclassdeclaresa
methodthathasthesametypeargumentsasamethoddeclaredbyoneofits
superclass.

Real Time Example of Polymorphism

Door of Church

Door of House

Allaredoors(One Interface or One Name)


Butalllooks different (Multiple Methods or Many
Forms)

Inheritance
Inheritanceisamechanismofacquiringthefeaturesand
behaviorsofaclassbyanotherclass.
The class whose members are inherited is called the
base class, and the class that inherits those members is
calledthederived class.
Types of Inheritance
Single Inheritance
Hierarchical Inheritance
Multi Level Inheritance
Hybrid Inheritance
Multiple Inheritance

Single Inheritance
whenasinglederivedclassiscreatedfromasinglebase
classthentheinheritanceiscalledassingleinheritance.

Hierarchical Inheritance
whenmorethanonederivedclassarecreatedfroma
singlebaseclass,thenthatinheritanceiscalledas
hierarchicalinheritance.

Multi Level Inheritance


Whenaderivedclassiscreatedfromanotherderivedclass,thenthat
inheritanceiscalledasmultilevelinheritance.

Hybrid Inheritance
Anycombinationofsingle,hierarchicalandmultilevelinheritances
iscalledashybridinheritance.

Multiple Inheritance
Whenaderived class iscreatedfrom more than one base class
thenthatinheritanceiscalledasmultipleinheritance.
Butmultipleinheritanceisnotsupportedby.NET using classesand
canbedoneusinginterfaces.

Situation For Inheritance


Inheritanceisagoodchoicewhen:

Your inheritance hierarchy represents an "is-a" relationship and


not a "has-a" relationship.

Youcanreuse code fromthebaseclasses.

Youneedtoapplythe same class and methods to different data


types.

The class hierarchy is reasonably shallow, and other developers


arenotlikelytoaddmanymorelevels.

Youwanttomakeglobal changes toderivedclassesbychanginga


base class.

Potrebbero piacerti anche