OOPS Training
Transcript of OOPS Training
-
7/29/2019 OOPS Training
1/37
OOP Fundamentals and Interview Questions
In case you are having issues regarding audio and video please
contact at [email protected] or you can call on thephone, these training are available as recordings later , please do not
disturb during training.
Please Mute your mic and mobile during training.
Ask your question using the Q and A tab in live meeting.
Speak one at a time so that every one is benefited.
www.DotNetFunda.Com
+www.Questpond.Com
mailto:[email protected]://www.dotnetfunda.com/http://www.questpond.com/http://www.questpond.com/http://www.dotnetfunda.com/mailto:[email protected] -
7/29/2019 OOPS Training
2/37
Agenda
A word about www.dotnetfunda.com Introduction
What's the problem with functional programming ?
OOP's Fundamentals
Abstraction
Encapsulation Inheritance
Polymorphism
Acces*s modifiers
Aggregation and Composition
Implementing OOPS in tiered architecture Most asked Inter*view questions in OOPS
http://www.dotnetfunda.com/http://www.dotnetfunda.com/ -
7/29/2019 OOPS Training
3/37
DotNetFunda.Com
DotNetFunda right from its commencement in the year 2007 has been
dedicated to render qualitative services to aid the IT community on an
assortment of technological facets/confronts and has been triumphant
thus far.
Looking at the incredible applauds from our users and visitors across the
globe on the services DotNetFunda has offered over the years; we are
committed to serve even better now.
We call you to help us in that direction and please participate more and
more in the website; either by asking questions, answering in the
Forums or writing articles, submitting interview questions and code
snippets.
Wishing you all the very best and a very good Luck.
-
7/29/2019 OOPS Training
4/37
Whats the problem with Functional
Programming ?
R eusability
E xtensibility
S implicity
M aintainability
Problem of Functional programming
RESM
-
7/29/2019 OOPS Training
5/37
Different copies of same code in
both the UI Increase inredundant code
-
7/29/2019 OOPS Training
6/37
New Functions created
rather than extending
Extensibility and simplicity Issues
-
7/29/2019 OOPS Training
7/37
Reusability
Extensibility
Simplicity
Maintainability
-
7/29/2019 OOPS Training
8/37
Can you define OOP and the 4 principles of OOP ?
Its a design philosophy where we visualize in terms of self sustained objects.
Classes and object
Reusability
Inheritance ,aggregation and composition
Extensibility
Abstraction , encapsulation and polymorphism
Simplicity
All the above 3 combined helps us to maintain the code better.
Maintainability
-
7/29/2019 OOPS Training
9/37
Maintainability
Simplicity
Extensibility Reusability
Classes
&
Objects
InheritanceaggregationComposition
All the above
combine tomake the codemaintainable
Abstraction
EncapsulationPolymorphism
Abstraction
Encapsulation
Polymorphism
Inheritance
-
7/29/2019 OOPS Training
10/37
Summarizing definition
Allows complex world to represented in a simplified manner byexposing only the necessary properties. For instance a color can beabstracted by RGB
Abstraction
Process of hiding inner details from the external world with thatmaking the object interface simple.Encapsulation
They are used to depict parent child relationship. So we can have aclass with just set and get , we can then inherit and create a newspecialized class which does database operations.Inheritance
We want a object to play different role depending on differentsituations. For instance we can class which does databaseoperations on SQL Server and Oracle. Depending on connectionstring it will MORPH its role to do SQL operations or Oracle
operations. Poly means many and morph means change
Polymorphism
Remember the word APIE
-
7/29/2019 OOPS Training
11/37
What are classes and objects ?
-
7/29/2019 OOPS Training
12/37
Addressesreusability
Classes and objects address reusability.
Think in termof objects
Rather than thinking in terms of functions think in terms of objects.
What is aclass ?
A class is simply a type of object. It is the blueprint/ plan/ template that describethe details of an object. A class is the blueprint from which the individual objectsare created. Class is composed of three things: a name, attributes, andoperations.
What isObject ?
Its an instance of a class. Class is brought live by creating objects. An object can
be considered a "thing" that can perform activities. The set of activities that theobject performs defines the object's behavior.
-
7/29/2019 OOPS Training
13/37
Class
Object
Class used as object
-
7/29/2019 OOPS Training
14/37
Same class reused in both UIs by creating objects
-
7/29/2019 OOPS Training
15/37
What is Inheritance ?
-
7/29/2019 OOPS Training
16/37
AddressesExtensibility
Inheritance addresses the problem ofextensibility.
Parent childrelationship
By using inheritance we can create afresh child class which has all the
qualities of parent plus some extra newqualities of himself also.
What is Inheritance ?
-
7/29/2019 OOPS Training
17/37
New Functions created
rather than extending
Problems Extensibility and simplicity Issues
-
7/29/2019 OOPS Training
18/37
Colon represent inheritance
clsProduct class is extended
and clsProductDicount class
is created using inheritance.
-
7/29/2019 OOPS Training
19/37
What is Polymorphism , overloading , overriding and virtual ?
-
7/29/2019 OOPS Training
20/37
Addresses Simplicity
By using polymorphism you can have more simplified interfaces and neatcode.
Meaning ofpolymorphism
'poly' means many, 'morphism' means forms. Its a ability of object ormethod to take different forms as per situation.
What is Polymorphism , overloading , overriding and virtual ?
-
7/29/2019 OOPS Training
21/37
Both the method names aresame but they act differently
as per inputs
This will invoke thecalculation of total cost with
out discount.
This will invoke the
calculation of total cost withdiscount.
-
7/29/2019 OOPS Training
22/37
Static Polymorphism
In Static Polymorphism the method to be called is decided at compile-timeonly. Method Overloading is an example of Static Polymorphism.
Dynamic Polymorphism
In dynamic polymorphism a call to a overridden function is resolved duringruntime. Dynamic polymorphism is acheived using inheritance and
overriding.
Two types of polymorphism
-
7/29/2019 OOPS Training
23/37
Both the method names aresame but they act differently
as per inputs
This will invoke thecalculation of total cost with
out discount.
This will invoke the
calculation of total cost withdiscount.
Static polymorphism is achieved by using method overloading
-
7/29/2019 OOPS Training
24/37
Parent Product class
Inherited Child Product class
Virtual keyword necessary to override the method
Override keyword necessary to define new implementation
Class inherited and getTotalCost overridden
with new functionality
-
7/29/2019 OOPS Training
25/37
clsProduct objProduct;
objProduct = new clsProduct();
objProduct.getTotalCost(intQty, intPerProductCost,"INR")
objProduct = new clsProductWithDiscount();
objProduct.getTotalCost(intQty, intPerProductCost,"INR")
This invokes the parent class code
This invokes the child class code
Dynamic polymorphism is achieved by using overriding
-
7/29/2019 OOPS Training
26/37
Can you explain encapsulation and abstraction ?
-
7/29/2019 OOPS Training
27/37
clsProduct obj = new clsProduct();
Obj. IsQuantityGreater (intQty);
Obj. isProductCostZero (intPerProductCost);
obj.PerProductCost = intPerProductCost;
obj.Quantity = intQty;
int totalCost = obj.getTotalCost(10,100);
clsProduct obj = new clsProduct();
obj.PerProductCost = intPerProductCost;
obj.Quantity = intQty;
Encapsulation means hiding complexity Extraexpos
edfunctionalities
.
Complicationencapsulated
-
7/29/2019 OOPS Training
28/37
Private: Only members of class have access.
Public: - All members have access in all classes andprojects
Protected:- All members in current class and in derivedclasses can access the variables.
Friend (internal in C#):- Only members in currentproject have access to the elements.
Protected friend (protected internal in C#) :- Allmembers in current project and all members inderived class can access the variables.
-
7/29/2019 OOPS Training
29/37
Abstraction, difference between abstraction and encapsulation?
Abstraction means show only what is necessary.
Abstraction and Encapsulation both compliment each
other.
Abstraction is achieved through encapsulation
Abstraction is achieved throughencapsulation..Abstraction solves the problem in thedesign side while encapsulation is the implementation.
-
7/29/2019 OOPS Training
30/37
What is an abstract class ?
-
7/29/2019 OOPS Training
31/37
Whats a abstract class ?Abstract classes represent base classes, and we can not create objects of these
classes.
An abstract class means that, no object of this class can be instantiated, but can
make derivations of this.
An abstract class can contain either abstract methods or non abstract methods.
Abstract members do not have any implementation in the abstract class, but the
same has to be provided in its derived class.
An abstract class cannot be a sealed or a static class.
You can make use of abstract classes to implement such functionality in C# using
the modifier 'abstract'.
-
7/29/2019 OOPS Training
32/37
An abstract class cannot be a sealed class.
An abstract method cannot be private.
The access modifier of the abstract method should be same in both the
abstract class and its derived class. If you declare an abstract method asprotected, it should be protected in its derived class. Otherwise, thecompiler will raise an error.
An abstract method cannot have the modifier virtual. Because an abstractmethod is implicitly virtual.
An abstract member cannot be static.
-
7/29/2019 OOPS Training
33/37
Define Interface and
Whats the difference between abstract and interface ?
-
7/29/2019 OOPS Training
34/37
Whats a interface ?
What are interfaces ?
An interface looks like a class, but has no implementation. It only contains definitions ofevents, indexers, methods and/or properties. The reason interfaces only providedefinitions is because they are inherited by classes and structs, which must provide animplementation for each interface member defined.
So what good are empty
methods
They help decoupling
Enforce standardization of vocabulary
-
7/29/2019 OOPS Training
35/37
Interface keyword is used to define interfaces.
Interface can not have field variables.
Interfaces can not have implemented functions and methods.
All methods in a interface needs to be implemented.
Interface can be used to implement run time polymorphism.
You can implement multiple interfaces.
All interface methods are public
-
7/29/2019 OOPS Training
36/37
Whats a difference between interfaces and abstract classes ?
An abstract class can have abstract members as well non abstractmembers. But in an interface all the members are implicitly abstract andall the members of the interface must override to its derived class.
The members of the interface are public with no implementation.Abstract classes can have protected parts, static methods, etc.
Abstract classes can add more functionality without destroying the childclasses that were using the old version. In an interface, creation ofadditional functions will have an effect on its child classes, due to thenecessary implementation of interface methods to classes.
Defining an abstract class with abstract members has the same effect todefining an interface.
-
7/29/2019 OOPS Training
37/37
Questions