Yes, Object Oriented Principals---> are rules a language which satificiates these rules(principals) are called object oriented language.
the basic object oriented principals are
Abstraction && Encapulation(Security).
Polymorphism(performance).
Inhertience(reuseablity).
......so Object Orieneted Programming is not only belong one any Specific language.
Ex : C#,Java,PHP..ect are object oriented languages.
Object Oriented Programming is a common Concept to all Programming languages.
--> the basic object oriented principals are
Abstraction && Encapulation(Security).
Polymorphism(performance).
Inhertience(reuseablity).
......so Object Orieneted Programming is not only belong one any Specific language.
Ex : C#,Java,PHP..ect are object oriented languages.
Object Oriented Programming is a common Concept to all Programming languages.
Abstraction and Encapsulation.
Abstraction is Encapsulation both are not same.
Abstraction(hiding the implementation)
whatever the things we don't require to know about hidden things are hidden is called abstraction. this is implementated in implictly.
General Example:
we are taking food.after taking food. we don't require to know about in our stomach how the food is processing (digestive process)in our stomak.(hiding the process…..abstraction)
This food gives some engry to work…like walk,stand,sit,sleep…ect.(relaving things…Encapulation)
So hiding the data(abstraction), relieving the data implementation(encapsulation) in a secured manner.
Coming to Technical:
We are creating Class this the basic pillar of our object oriented programming. The default scope of the Class is internal (this class is accessible till that project only)
We can’t consume the type(class) directly so we are creating object to that class.
Example :
class name is Artimetics
Class Artimetics // Internal
{
Int AddNumber s(int x,int y); //Private
Int SumNumbers(int x,int y); //Private
}
We have one reference type called Artimetics.
What is Reference type?
We know premetive/sclare types : int,float,double…all are derived from System.ValueType.
How to store a value in these types
int id=101;
Here id is of type Integer. So we are storing the data in Integer type. So datatypes it can be premetive or sclar or reference. So we need to take those apporite type variables.
Here also I want to store Artimetics details so I am creating Artimetics type variable that is called as object.
We need to use new keyword in order to create objects why because those are reference type.
Artimetics robj=new Artimetics ();
Int addresult = robj.AddNumbers(10,20);
Int sumresult = robj.SumNumbers(40,10);
Encapulation is achived with the help of Methods,Properties.
Object is called robj process the data(Abstraction) as per method name and returns the result with the help of methods of that type.(Encapsulation).
Polymorphism
What is polymorphism?Giving multiple forms to same object is the processing is called polymorphism.
General Ex
One Person(name as anand) developing one entire project.
He did all the work same person
Created database work,
Design the Pages,
Write the Coding
So the same person doing all these works ok
Here
How is sql developer----anand
How is web designer-----anand
How is Application Develoeper-----anand
So as per requirement of the project anand--à a single person behaves like 3 persons as per Project requirements.
Coming to Technical:
In the Artimetic Class we have a method is used to add 2 numbers method. But I want to add 3 numbers.
so instead of creating one more method with the different name
AddThreeNumbers(int x,int y,int z)
AddFourNumbers(int x,int y,int z int m)
….. to making standarzation and improve the performance
Polymorphism provides 3 approaches
Method overloading
Method overriding.
Method hiding(showding in vb.net)
Method Overloading :
In this approach we can define a method with different signatures with same Method name.
Like below
In derived classes also we can override the existing methods for this we require an Expliect Permission from the parent class.
In this approach we can override existing functionality In derived classes but method signature should be same.
So define the methods with the keyword ---à virtual keyword.
In derived class override the methods with the keyword--à override keyword.
Like below
output :
Considers in the Method overloading:
Method Parameters should be different
-> Test(int x);
-> Test(string s);
Method Parameters order should be different.\
--> Test(int x, string s);
--> Test(string s, int x);
No’ f parameters should be different.
--> Test(int x, int y);
--> Test(int x, int y,int z);
Method Overrideing:
Providing more functionality in derived classes with same signature is called overriding.
We will discuss more in inhertience concept.
in the above example 4th method with 4 parameters is overloading method.
Considerations Method Overloading :
Method overloading is possible is in derived classes only.
Inhertience(code reusebility)
Inhertience is used to code reusability.
Class Class1
{
Int Add(int x,int y)
}
Class Class2: Class1
{
Int Sub(int x,int y);
}
----this is single inhertience
Class1 is derived by Class2.
One single class is derived by single class.--->so it is Single Inhertience.
Class Class3:class2,class1
{
Int Mul(int m,int n,int o)
}
Class1,class2 are derived by class3------à this also Single Inhertience
so many are said we have single,multilevel,multiple(not support in c#),hybrid…but every thing is finally
it is a single inhertience only.
Coming to Point of Inhertience :
When we create object of derived class we can utilize the parent class methods also with the help of
but we can' t access the child class members through parent class object.Conculation is:
Abstraction and Encapulation are Hiding the data(abstraction) and Relieving the data in Secured manner(Encapsulation).
Inhertience is used to resue existing funcationalities, and providing additional functionalities.
No comments:
Post a Comment