real time example in oops

33
OOP Concept with Real Time Exapmles OOP is a design philosophy. It stands for Object Oriented Programming.Object-Oriented Programming (OOP) uses a different set of programming languages than old procedural programming languages. Everything in OOP is grouped as self sustainable "objects". Hence, you gain re-usability by means of four main object-oriented programming concepts. The object oriented programming (OOP) is a programming model where Programs are organized around object and data rather than action and logic. In order to clearly understand the object orientation, let’s take your “Leg” as an example. The “Leg” is a class. Your body has two objects of type Leg, named left Leg and right Leg. Their main functions are controlled/ managed by a set of electrical signals sent through your body parts(through an interface). So the body part is an interface which your body uses to interact with your Legs. The Leg a well architect ed class. The Leg is being re-used to create the left Leg and the right Leg by slightly changing the properties of it. Now we can go through the concepts, Class Class is the core of any modern OOP language. We must create a class for representing Data. A user-defined data structure that groups properties and methods. A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object. A class is the blueprint from which the individual objects are created. Class is composed of three things: a name, attributes, and operations. Class doesn’t occupies memory. Its a logical representation of Data. class Leg { } Object

description

real time example in oops

Transcript of real time example in oops

Page 1: real time example in oops

OOP Concept with Real Time ExapmlesOOP is a design philosophy. It stands for Object Oriented Programming.Object-Oriented Programming (OOP) uses a different set of programming languages than old procedural programming languages. Everything in OOP is grouped as self sustainable "objects". Hence, you gain re-usability by means of four main object-oriented programming concepts. The object oriented programming (OOP) is a programming model where Programs are organized around object and data rather than action and logic. 

  In order to clearly understand the object orientation, let’s take your “Leg” as an example. The “Leg” is a class. Your body has two objects of type Leg, named left Leg and right Leg. Their main functions are controlled/ managed by a set of electrical signals sent through your body parts(through an interface). So the body part is an interface which your body uses to interact with your Legs. The Leg a well architect ed class. The Leg is being re-used to create the left Leg and the right Leg by slightly changing the properties of it.

Now we can go through the concepts,

ClassClass is the core of any modern OOP language. We must create a class for representing Data. A user-defined data structure that groups properties and methods. A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object. A class is the blueprint from which the individual objects are created. Class is composed of three things: a name, attributes, and operations. Class doesn’t occupies memory. Its a logical representation of Data.

class Leg{}

ObjectInstance of Class is called object.We can use "new" keyword for creating objects.Class will not occupy any memory space. Hence to work with thedata represented by the class you must create a variable for the class, which is called as an object. 

Page 2: real time example in oops

When we use "new" keyword for creating object, then memory will be allocated for the class in heap, we can call an instance and its starting address will be stored in the object in stack. When an object is created without the keyword new, then memory will not be allocated in heap Means instance of the object wont create and object in the stack havenull value. When an object contains null, then it is not possible to access the members of the class with that object.Leg objLeg = new Leg(); In fact classes describe the type of objects, while objects are usable instancesof classes. Struct and ClassStruct is value type while class is reference type.Struct stored in Stack Class stored in Heap.Struct wont support Inheritance but class Support.Struct using for Simple/small data structure class is a better choice for complex data structure.A class and Struct can implement more than one interface. The fact that a Struct can implement an interface is well known and so is the fact that casting a value type into an interface leads to boxing of the value type. Boxing and Un-Boxing

Boxing: means converting value-type to reference-type.

UnBoxing: means converting reference-type to value-type.

this KeywordEach object has a reference “this” which points to itself.Uses of this keyword

are,o Use to refer to the current object.o we also can use by one constructor to explicitly invoke another constructor of

the same class.Eg:class Leg{   private string legname;   private int number;  Student(string name, int num) {   this.legname= name;   this.number= num;  } }

Page 3: real time example in oops

Abstraction

Abstraction is the process of hiding how the object is working, and its only showing the information of the object the way we can understand it. Means it represent the essential details with out showing ground details. We putting all variables and method in a class which are necessary.

Eg: Employee and Patient.

Company interested to fill about the Employee details like Name, Address, Qualification, DOB, Age, Mobile, Marks, Experience etc

Hospital interested to fill  about the patient details like Name, DOB, Height,  Weight, Age, Address, Mobile, Blood Group etc.

Both Company and hospital interested to fill some common fields like Name, Age, DOB, Address, Mobile etc. So we can create a class which consist of common thing that is called abstract class. This class wont be complete but can inherit by other class.

Difference between Abstraction and Interface please refer:  

http://jom-george.blogspot.in/2011/03/what-is-difference-between-abstract.html

Encapsulation: Wrapping up data member and method together into a single unit (i.e. Class) is called Encapsulation. 

 Eg: we can consider a capsule. Encapsulation means hiding the internal details of an object, i.e. how an object does something. Here capsule is a single Unit contain many things. But we cant see what is there in side capsule. 

Page 4: real time example in oops

  This is the technique used to protect information about an object from other objects. Like variable we can set as private and property as Public. When we access the property then we validate and set it.

 We can go through some other examples. Our Laptop. We can use Laptop but what operations are happening inside that we are not knowing. But we can use that. Same like mobile, TV etc. 

We can conclude that a group of related properties, methods, and other members are treated as a single unit or object.An encapsulated object is often called an abstract data type. 

There are several other ways that an encapsulation can be used, as an example we can take the usage of an interface. The interface can be used to hide the information of an implemented class. //Declare as Privateprivate string _LegName;// Property Set as publicpublic string LegName{get{return _LegName;}set {_LegName=value;}

public class LegMain{public static int Main(string[] args){Leg L= new Leg();d.LegName="Right Leg";Console.WriteLine("The Legis :{0}",d.LegName);return 0;}  

Note: Encapsulation provides a way to protect data from accidental corruption. 

Constructor  A special method of the class that will be automatically invoked when an instance of the class is created is called as constructor.    

Page 5: real time example in oops

Constructors can be classified into 5 types

1. Default Constructor2. Parameterized Constructor3. Copy Constructor4. Static Constructor5. Private Constructor 

Default Constructor : A constructor without any parameters is called as default constructor. Drawback of default constructor is every instance of the class will be initialized to same values and it is not possible to initialize each instance of the class to different values.Parameterized Constructor : A constructor with at least one parameter is called as parameterized constructor. Advantage of parameterized constructor is you can initialize each instance of the class to different values.

Class Leg(){  //default Constructor        public Leg()        {            Name = "Left";            Num = 2;        }

  //Parametrized Constructor        public Leg(string Name, int Num)        {            LegName = Name;            LegNum = Num;        }} 

 static void Main() {

  Leg L1 = new Leg();  //Default Constructor is called  Leg L2= new Leg("Left",2);//Parametrized Constructor is called                L1.Print();        L2.Print();

Page 6: real time example in oops

     Console.Read();           }Copy Constructor : A parametrized constructor that contains a parameter of same class type is called as copy constructor. Main purpose of copy constructor is to initialize new instance to the values of an existing instance.  class Leg    {        string A;        int B;         public Leg(string I, int J)        {            A = I;            B = J;        }

        //Copy Constructor        public Leg(Leg T)        {            A = T.A;             B = T.B;        }             public void Print()        {

            Console.WriteLine("{0}{1}", A, B);        }   

    }

    class CopyConstructor    {        static void Main()        {          

            Leg L = new Leg ("Left", 2);

Page 7: real time example in oops

            //Invoking copy constructor            Leg T1 = new Leg (L);                       L.Print();            L1.Print();             Console.Read();        }    }Static Constructor : You can create a constructor as static and when a constructor is created as static, it will be invoked only once for any number of instances of the class and it is during the creation of first instance of the class or the first reference to a static member in the class. Static constructor is used to initialize static fields of the class and to write the code that needs to be executed only once.

Private Constructor : You can also create a constructor as private. When a class contains at least one private constructor, then it is not possible to create an instance for the class. Private constructor is used to restrict the class from being instantiated when it contains every member as static.

A class can have any number of constructors. A constructor doesn’t have any return type even void. A static constructor can not be a parameterized constructor. Within a class you can create only one static constructor.

destructor  A destructor is a special method of the class that is automatically invoked while an instance of the class is destroyed. Destructor is used to write the code that needs to be executed while an instance is destroyed. To create a destructor, create a method in the class with same name as class preceded with ~ symbol.

Syntax :

~Leg(){ }What is the difference between the destructor and the Finalize() method? When does the Finalize() method get called? Finalize() corresponds to the .Net Framework and is part of the System.Object class. Destructors are C#'s implementation of the

Page 8: real time example in oops

Finalize() method. The functionality of both Finalize() and the destructor is the same, i.e., they contain code for freeing the resources when the object is about to be garbage collected. In C#, destructors are converted to the Finalize() method when the program is compiled. The Finalize() method is called by the .Net Runtime and we can not predict when it will be called. It is guaranteed to be called when there is no reference pointing to the object and the object is about to be garbage collected.Inheritance

In the real world there are many objects that can be specialized. In OOP, a parent class can inherit its behavior and state to children classes. This concept was developed to manage generalization and specialization in OOP and is represented by a is-a relationship.The following OO terms are commonly used names given to parent and child classes in OOP:

Superclass: Parent class. Subclass: Child class. Base class: Parent class. Derived class: Child class Inheritance makes code elegant and less repetitive.Syntax: class child: parent   Types of Inheritance

1. Single Inheritance2. Hierarchical Inheritance3. Multi Level Inheritance4. Hybrid Inheritance5. Multiple Inheritance

Multiple inheritance is the possibility that a child class can have multiple parents. Human beings have always two parents, so a child will have characteristics from both parents. Single Inheritance the child can have only one parent class and viz.When more than one derived class are created from a single base class, then that inheritance is called as hierarchical inheritance.When a derived class is created from another derived class, then that inheritance is called as multi level inheritance.Any combination of single, hierarchical and multi level inheritances is called as hybrid inheritance.

Sealed class

Page 9: real time example in oops

A sealed class is a class that does not allow inheritance. Some object model designs need to allow the creation of new instances but not inheritance, if this is the case, the class should be declared as sealed.

To create a sealed class in C#, the class declaration should be done as:sealed class Shape

Polymorphism

Through inheritance, a class can be used as more than one type; it can be used as its own type, any base types, or any interface type if it implements interfaces. This is called polymorphism.

Polymorphism means having more than one form. Overloading and overriding are used to implement polymorphism. Polymorphism is classified into compile time polymorphism or early binding or static binding and Runtime polymorphism or late binding or dynamic binding.

Overriding - same method names with same arguments and same return types associated in a class and its subclass. Overriding in C# makes use of the "override" keyword. To override a method means to replace it with a new way of handling data. 

Overloading - same method name with different arguments, may or may not be same return type written in the same class itself. 

Compile time Polymorphism or Early Binding 

The polymorphism in which compiler identifies which polymorphic form it has to execute at compile time it self is called as compile time polymorphism or early binding. 

Advantage of early binding is execution will be fast. Because every thing about the method is known to compiler during compilation it self and disadvantage is lack of flexibility. 

Examples of early binding are overloaded methods, overloaded operators

Page 10: real time example in oops

and overridden methods that are called directly by using derived objects. 

Runtime Polymorphism or Late Binding 

The polymorphism in which compiler identifies which polymorphic form to execute at runtime but not at compile time is called as runtime polymorphism or late binding. 

Advantage of late binding is flexibility and disadvantage is execution will be slow as compiler has to get the information about the method to execute at runtime.

Example of late binding is overridden methods that are called using base class object.Clas A{      Virtual void Leg(string Name){

Class B:A{  public overrid void Leg(String Name)  {

  }}

Example for Over loading

Class A{    class a()   {   }   class a(String Name)   {   }}

Page 11: real time example in oops

In other words, "Many forms of a single object is called Polymorphism."

Eg: 

A Team Leader behaves to Sub Ordinate.A Team Leader behaves to his/her seniors.A Team Leader behaves to other Team Leaders.  

Here Team Leader is an object but attitude is different in different situation. 

Difference between Method Overriding and Method hidingMethod overriding allows a subclass to provide a specific implementation of a method that is already provided by base class. The implementation in the subclass overrides (replaces) the implementation in the base class.The important thing to remember about overriding is that the method that is doing the overriding is related to the method in the base class.When a virtual method is called on a reference, the actual type of the object to which the reference refers is used to determine which method implementation should be used. When a method of a base class is overridden in a derived class (subclass), the version defined in the derived class is used. This is so even should the calling application be unaware that the object is an instance of the derived class.Method hiding does not have a relationship between the methods in the base class and derived class. The method in the derived class hides the method in the base class.

Sealed keyword can be used to stop method overriding in a derived classes.By default, all methods a sealed, which means you can't override them, so that "sealed" keyword is redundant in this case and compiler will show you error when you'll try to make sealed already sealed method. But if your method was marked as virtual in a base class, by overriding and marking this method with "sealed" will prevent method overriding in derived classes.

Conclusion  

Oops features make you to continue forward as the most effective programmers in the most productive programming language.

Page 12: real time example in oops

Polymorphism:

Example of Compile Time Polymorphism

Method Overloading- Method with same name but with different arguments is called method overloading.- Method Overloading forms compile-time polymorphism.- Example of Method Overloading:class A1{void hello(){ Console.WriteLine("Hello"); }

void hello(string s){ Console.WriteLine("Hello {0}",s); }}

Example of Run Time Polymorphism

Method Overriding- Method overriding occurs when child class declares a method that has the same type arguments as a method declared by one of its superclass.- Method overriding forms Run-time polymorphism.- Note: By default functions are not virtual in C# and so you need to write "virtual" explicitly. While by default in Java each function are virtual.- Example of Method Overriding:Class parent{virtual void hello(){ Console.WriteLine("Hello from Parent"); }}

Class child : parent{override void hello(){ Console.WriteLine("Hello from Child"); }}

static void main(){parent objParent = new child();objParent.hello();}//OutputHello from Child.

Use of WPF?Programs that need access to Windows desktop files.The Windows Presentation Foundation (WPF) is a graphical display system for Windows.

Page 13: real time example in oops

WPF is designed for .NET, influenced by modern display technologies such as HTML and Flash, and hardwareaccelerated.It’s also the most radical change to hit Windows user interfaces since Windows 95.A standard Windows application relieson two well-worn parts of the Windows operating system to create its user interface:User32. This provides the familiar Windows look and feel for elements such aswindows, buttons, text boxes, and so on.GDI/GDI+. This provides drawing support for rendering shapes, text, and imagesat the cost of additional complexity (and often lackluster performance).The following are some of the most dramatic changes that WPF ushers into the Windows programming world:A web-like layout model. A rich drawing model. A rich text model. Animation as a first-class programming concept. Support for audio and video media. Styles and templates. Commands. Declarative user interface. Page-based applications.Microsoft almost had 3 to 4 API's for display technologies , so why a need for one more display technology. DirectX had this excellent feature of using hardware acceleration. Microsoft wanted to develop UI elements like textboxes,button,grids etc using the DirectX technology by which they can exploit the hardware acceleration feature. As WPF stands on the top of directX you can not only build simple UI elements but also go one step further and develop special UI elements like Grid, FlowDocument, and Ellipse. Oh yes you can go one more step further and build animations.WPF is not meant for game development. DirectX still will lead in that scenario. In case you are looking for light animation ( not game programming ) WPF will be a choice. You can also express WPF using XML which is also called as XAML.In other words WPF is a wrapper which is built over DirectX. So let’s define WPF.

What is the difference between XML Web Services using ASMX and .NET Remoting using SOAP?

XML Web services are more restricted than objects exposed over .NET Remoting.

XML Web services support open standards that target cross-platform use.

XML Web services are generally easier to create and due to the restricted nature of XML Web services, the design issues are simplified.

XML Web services support only SOAP message formatting, which uses larger XML text messages.

Communication with .NET Remoting can be faster than XML Web service communication with a binary formatter.

XML Web services are designed for use between companies and organizations.

XML Web services don't require a dedicated hosting program because they are always hosted by ASP.NET.

Consumers can use XML Web services just as easily as they can download HTML pages from the Internet. Thus there's no need for an administrator to open additional ports on a firewall as they work through MS-IIS and ASP.NET

.NET Remoting isn't implemented with much concern for interoperability. Services implemented using .NET

Page 14: real time example in oops

Remoting, even if they use an open standard like SOAP as the transport layer, cannot be consumed by non-.NET clients.

Advantages of Silver Light It compel cross-platform user experiences.

It has Flexible programming model with collaboration tools.It outputs High-quality media and with a low-cost delivery.It can be Connected to data, servers, and services.Compared to WPF, you get no hardware acceleration and no 3D.With Silverlight you get cross platform (almost all browsers on Mac and Windows) .NET runtimes, where WPF is Windows only.With WPF (XBAP), you can not script against it or have your XBAP "talk" to the HTML DOM. In Silverlight, your have full communication between your web page and your silverlight application. You can even run your js under Silverlight for a massive performance increase because it will compile under the .NET CLR (Silverlight v1.1). Lets not forget C# in the browser...We can have multiple XAML files in SIlverlight Project. SOme other main advantages:-1)Development IDE :- The development IDE for Silverlight2 is Visual Studio 2008. Bar none, Microsoft has the best development IDE on the market. Whether you are programming are a C++, C or Java programmer, you will learn to envy Visual Studio 2008. A lot of the items that I will post below can have constructive arguments. However, this is one of the few that is iron clad. There simply is NO comparison between Visual Studio 2008 and Adobe Flex Builder3.2).NET Framework & Languages (C#, VB.NET and dynamic languages):- Silverlight 2 runs on a subset of the .NET 3.5 Framework. Therefore, it requires a the use of a .NET based language. The two flagship languages in .NET are C# and VB.NET. Flex uses ActionScript. If you are a .NET/Microsoft development department, you already have the majority of the skills necessary to start developing in Silverlight! That is a huge advantage over Adobe's counterpart. Silverlight also supports writing applications in dynamic languages such as Iron Ruby.3. Intergration with Enterprise based technologies:- Silverlight 2 integrates very well with other Enterprise Microsoft .NET based technologies. Silverlight 2 is not a technology that is out there on its own fending for itself. Microsoft did a real good job integrating the technology with its other enterprise offerings. I am going to cover just a couple biggies:WCF:-The ability to use: WCF basicHttpBinding, duplex binding and WCF REST services is huge. WCF allows architects to create a first class Service Oriented Architecture and it can be consumed by Silverlight clients. Adobe has nothing of the sort. Flash and Flex obviously can consume web services/REST services etc. However, the entire WCF framework gives Silverlight a big advantageLINQ:- Silverlight just like Flash/Flex are client side technologies. In the Web 2.0-3.0 days a good design is to minimize calls to the server and try to manipulate some of the data on the client. LINQ works inside Silverlight. It is a VERY powerful architecture option to be able to manipulate data structures fast and efficiently on the client rather than having to rely on the server. This gives Silverlight simply a huge advantage in productivity and architectual capabilities.4. Perception as an RIA business framework:- Perception is everything. When I speak to other developers about Silverlight, they are generally very excited and

Page 15: real time example in oops

motivated to learn the technology. Why? It essentially is very similar to Flash, which has been around for several years now. It is all about perception. For example, lets look at the iPhone when it launched last year (2007). Everyone and their mother lined up to get one, even though the phone was lacking major mobile technology that had been around for a couple years prior. Another example is VB.NET vs C#. VB.NET has always been looked as the red headed step child in .NET when compared to C#. C# has the perception of a more mature, professional and advanced language. This is where I think Silverlight has a huge perception/marketing edge. For creating business applications you will probably find it a lot more developers, architects and dev managers rallying around and more comfortable with Silverlight rather than Flex.5. Microsoft has Windows:-)Like it or not, Microsoft still controls 85%+ of the desktop market. That percentage is even greater on business workstations. Even though Flash/Flex has a huge market lead now, Microsoft can simply put a monsterous dent in it by releasing Silverlight 2 RTM as a hotfix, part of a Service Pack or part of the next Windows release. Microsoft can simply distribute the Silverlight 2 RIA framework on a level no other company can. Many IT engineers will like Silverlight since it is a Microsoft based technology. It will make it a lot easier to distribute to their employees.6. Mesh:- Mesh right now is Microsoft's offering to sync up data between computers. It uses Silverlight as the UI. Unless you have been sleeping under a rock, you probably have heard Microsoft tried to buy Yahoo multiple times and tried to essentially buy their way into the search/advertising market. This is one area where since 1995 both Web 1.0 and Web 2.0 have both passed Microsoft by. Mesh is going to be Microsoft's big splash into Web 3.0 and the semantic web/cloud computing and allow them to compete with Google, Yahoo, FaceBook. What is great is that Silverlight is the UI for this huge "Internet 2" technology.

What is the difference between Finalize() and Dispose()? Dispose() is called by as an indication for an object to release any unmanaged

resources it has held.Finalize() is used for the same purpose as dispose however finalize doesn’t assure the garbage collection of an object.Dispose() operates determinalistically due to which it is generally preferred.

A type's Dispose method should release all the resources that it owns. It should also release all resources owned by its base types by calling its parent type's Disposemethod. The parent type's Dispose method should release all resources that it owns and in turn call its parent type's Dispose method, propagating this pattern through the hierarchy of base types. To ensure that resources are always cleaned up appropriately, a Dispose method should be callable multiple times without throwing an exception.

A Dispose method should call the GC.SuppressFinalize method for the object it is disposing. If the object is currently on the finalization queue, GC.SuppressFinalizeprevents its Finalize method from being called. Remember that executing a Finalizemethod is costly to performance. If your Dispose method has already done the work to clean up the object, then it is not necessary for the garbage collector to call the object'sFinalize method.

Page 16: real time example in oops

A Finalize method should not throw exceptions, because they cannot be handled by the application and can cause the application to terminate.

The garbage collector keeps track of objects that have Finalize methods, using an internal structure called the finalization queue. Each time your application creates an object that has a Finalize method, the garbage collector places an entry in the finalization queue that points to that object.

http://mvkr.blogspot.in/2010/07/oops-concepts-with-real-time-examples.htmlhttp://www.c-sharpcorner.com/UploadFile/tusharkantagarwal/objectorientedcsharp11162005070743AM/objectorientedcsharp.aspxhttp://renganathan1984.blogspot.in/http://www.aspdotnet-suresh.com/2010/04/introduction-to-object-oriented.html

http://manishagrahari.blogspot.in/2011/08/oops.htmlhttp://aspnettutorialonline.blogspot.com/2012/06/aspnet-c-sql-server-ajax-interview.html

http://dotnetguts.blogspot.in/2007/07/example-of-polymorphism-in-net.html

Polymorphism

What is Polymorphism? Polymorphism is one of the primary characteristics (concept) of object-oriented

programming. Poly means many and morph means form. Thus, polymorphism refers to being able to

use many forms of a type without regard to the details. Polymorphism is the characteristic of being able to assign a different meaning

specifically, to allow an entity such as a variable, a function, or an object to have more than one form.

Polymorphism is the ability to process objects differently depending on their data types. Polymorphism is the ability to redefine methods for derived classes.

Types of Polymorphism Compile time Polymorphism Run time Polymorphism

Compile time Polymorphism

Page 17: real time example in oops

Compile time Polymorphism also known as method overloading Method overloading means having two or more methods with the same name but with

different signatures

Example of Compile time polymorphism

Run time Polymorphism

Run time Polymorphism also known as method overriding Method overriding means having two or more methods with the same name , same

signature but with different implementation

Example of Run time Polymorphism

Example of Polymorphism in .Net

What is Polymorphism?Polymorphism means same operation may behave differently on different classes.Example of Compile Time Polymorphism: Method OverloadingExample of Run Time Polymorphism: Method Overriding

Example of Compile Time Polymorphism

Method Overloading- Method with same name but with different arguments is called method overloading.- Method Overloading forms compile-time polymorphism.- Example of Method Overloading:

Page 18: real time example in oops

class A1{void hello(){ Console.WriteLine(“Hello”); }

void hello(string s){ Console.WriteLine(“Hello {0}”,s); }}

Example of Run Time Polymorphism

Method Overriding- Method overriding occurs when child class declares a method that has the same type arguments as a method declared by one of its superclass.- Method overriding forms Run-time polymorphism.- Note: By default functions are not virtual in C# and so you need to write “virtual” explicitly. While by default in Java each function are virtual.- Example of Method Overriding:Class parent{virtual void hello(){ Console.WriteLine(“Hello from Parent”); }}

Class child : parent{override void hello(){ Console.WriteLine(“Hello from Child”); }}

static void main(){parent objParent = new child();objParent.hello();}//OutputHello from Child.

Abstraction

Page 19: real time example in oops

What is an Abstraction?. Abstraction is thinking about something a certain way. Abstraction is the representation of only the essential features of an object and hiding un essential features of an object.. Through Abstraction all relevant data can be hide in order to reduce complexity and increase efficiency. Abstraction is simplifying complex reality by modeling classes appropriate to the problem. Abstraction-outer layout, used in terms of design. Encapsulation protects abstraction.. It taking required data and hiding the unwanted data.

In this above example abstraction shows only necessary details of car or shows only necessary details to drive a car like rear view mirror, gear, clutch, steering And hides internal detail of car like Piston, crankshaft, carburetors, gas turbines etc which is encapsulation for a car.

Abstraction shows only required data and hides unwanted data.Difference between Encapsulation and Abstraction

1. Abstraction solves the problem in the design level

1. Encapsulation solves the problem in the implementation level

2. Abstraction is used for hiding the unwanted data and giving relevant data

2. Encapsulation means hiding the code and data in to a single unit to protect the data from outside world

3. Abstraction is a technique that helps to identify which specific information should be visible and which information should be hidden.

3. Encapsulation is the technique for packaging the information in such a way as to hide what should be hidden, and make visible what is intended to be visible.

Page 20: real time example in oops

In this above example abstraction shows only necessary details of car or shows only necessary details to drive a car like rear view mirror, gear, clutch, steering And hides internal detail of car like Piston, crankshaft, carburetors, gas turbines etc which is encapsulation for a car

Abstraction shows only required data and hides unwanted data .

In above example which shows encapsulated detail of a car which is not necessary to expose to outside world and make visible what is intended to be visible.

Encapsulation

What is Encapsulation? Encapsulation is one of the fundamental principles of object-oriented programming. Encapsulation is a process of hiding all the internal details of an object from the outside

world Encapsulation is the ability to hide its data and methods from outside the world and

only expose data and methods that are required Encapsulation is a protective barrier that prevents the code and data being randomly

accessed by other code or by outside the class Encapsulation gives us maintainability, flexibility and extensibility to our code.

Page 21: real time example in oops

Encapsulation makes implementation inaccessible to other parts of the program and protect from whatever actions might be taken outside the function or class.

Encapsulation provides a way to protect data from accidental corruption Encapsulation hides information within an object Encapsulation is the technique or process of making the fields in a class private and

providing access to the fields using public methods Encapsulation gives you the ability to validate the values before the object user change

or obtain the value Encapsulation allows us to create a "black box" and protects an objects internal state

from corruption by its clients.

Two ways to create a validation process. Using Accessors and Mutators

Using properties

In this example _employeeid and _salary is private fields and providing access to the fields using public methods (SetEmployeeID,GetEmployeeID,SetSalary,GetSalary)

Benefits of Encapsulation In Encapsulation fields of a class can be read-only or can be write-only

Page 22: real time example in oops

A class can have control over in its fields A class can change data type of its fields anytime but users of this class do not need to

change any code

Inheritance

What is Inheritance?Inheritance, together with encapsulation and polymorphism, is one of the three primary characteristics (concept) of object-oriented programming Inheritance enables you to create new classes that reuse, extend, and modify the behavior that is defined in other classes The Class whose methods and variables are defined is called super class or base class The Class that inherits methods and variables are defined is called sub class or derived class Sometimes base class known as generalized class and derived class known as specialized class Keyword to declare inheritance is ":" (colon) in visual C#.

Benefits of using InheritanceOnce a behavior (method) or property is defined in a super class(base class),that behavior or property is automatically inherited by all subclasses (derived class). Code reusability increased through inheritance Inheritance provide a clear model structure which is easy to understand without much complexity Using inheritance, classes become grouped together in a hierarchical tree structure Code are easy to manage and divided into parent and child classes

Types of Inheritance in C#: - Implementation Inheritance Multiple Inheritances (Interface Inheritance)

Page 23: real time example in oops

Implementation InheritanceOne base class (super class) and one derived class (sub class).Example:

Interface InheritanceAn interface looks like a class, but has no implementation. It contains definitions of events, indexers, methods and properties. An interface inherited by classes An interface inheritance defined with keyword "interface". In C# Interface Inheritance also known as multiple inheritances.Inheritance Tree Structure:

OOPS Basic

What is an object? An object is a software bundle of variables and related methods. Objects are related to real life scenario Class is the general thing and object is the specialization of general thing Objects are instance of classes. Declaration of an Object in C#.NET ClassName objectName=new ClassName();

Page 24: real time example in oops

E.g.: Person objPerson= new Person();

An object is characterized by concepts like: Attribute Behavior Identity

1. What is an Attribute? Attributes define the characteristics of a class. The set of values of an attribute of a particular object is called its state. In Class Program attribute can be a string or it can be a integer

2. What is a Behavior? Every object has behavior In C#, behaviors of objects are written in methods. If a behavior of an object needs to be performed, then the corresponding method is

called.

3. What is an Identity? Each time an object is created the object identity is been defined. This identity is usually created using an identifier which is derived from the type of item

Difference Between Web Farm and Web Garden

Introduction

Web Farms and Web Garden are very common terminology for any production deployment. Though these terms looks same but the things are totally different. Many beginners very confused with these two terms. Here I am giving the basic difference between the Web Farm and Web Garden.

Web Farm

After developing our asp.net web application we host it on IIS Server.  Now one standalone server is sufficient to process ASP.NET Request and response for a small web sites but when the site comes for big organization where there an millions of daily user hits then we need to host the sites on multiple Server. This is called web farms. Where single site hosted on multiple IIS Server and they are  running behind the Load Balancer.

Page 25: real time example in oops

Fig : General Web Farm Architecture

This is the most common scenarios for any web based production environment. Where Client will hit an Virtual IP ( vIP) . Which is the IP address of Load Balancer. When Load balancer received the request based on the server load it will redirect the request to particular Server.

Web Garden

All IIS Request process by worker process ( w3wp.exe). By default each and every application pool contain single worker process. But An application pool with multiple worker process is called Web Garden.   Many worker processes with same Application Pool can sometimes provide better throughput performance and application response time. And Each Worker Process Should have there own Thread and Own Memory space.

Page 26: real time example in oops

There are some Certain Restriction to use Web Garden with your web application. If we use Session Mode to "in proc", our application will not work correctly because session will be handled by different Worker Process. For Avoid this Type of problem we should have to use Session Mode "out proc" and we can use "Session State Server" or "SQL-Server Session State".

How To Configure Web Garden?

Right Click on Application Pool > Properties > GoTo Performance Tab In bottom Group Section  Increase the Worker Process Count.

Further Study

1. http://www.codeproject.com/KB/aspnet/ExploringIIS.aspx

What is the difference between web farm and web garden in asp.net?Answer :

 Web Farm: It is a multi-server scenario and we can keep servers separately. If the load on one server is in excess then the other servers step in to bear the strength. Server Load is based on various following models.1. Round Robin. (All servers share load equally)2. Network Load Balancer (economical) 3. HLB (expensive but can scale up to 8192 servers)4. Hybrid (2 and 3).5. CLB (Component load balancer).

We can implement web farms in .NET. Open web.config file and add mode options.i) if mode=inproc (non web farm but fast when you have very few customers).ii) if mode=StateServer (for web farm)iii) if mode=SqlServer (for web farm)Whether to use option (ii) or (iii) depends on situation. StateServer is faster but SqlServer is more reliable and used for critical applications.

Web Garden: It is a multi-processor setup i.e. in case of a web garden we have a one server having more than one processor. You can use web gardens in .Net as: Open web.config file and add webGarden = true in processmodel tag.

Web-garden - An IIS6.0 feature where you can configure an application pool as a web-garden and also specify the number of worker processes for that pool. It can help improve performance in some cases.

Page 27: real time example in oops

Web-farm - a general term referring to a cluster of physically separate machines, each running a web-server for scalability and performance (contrast this with web-garden which refers to multiple processes on one single physical machine).