ASP.NET: Object Oriented Programing - Key Concepts of Object Orientation

ASP.NET: Object Oriented Programing - Key Concepts of Object Orientation

The basic building blocks of object-oriented programming are the class and the object. A class defines the available characteristics and behaviour of a set of similar objects and is defined by a programmer in code. A class is an abstract definition that is made concrete at run-time when objects based upon the class are instantiated and take on the class' behaviour.

Key Concepts of Object Orientation

  • Object
  • Class
  • Abstraction
  • Encapsulation
  • Data Hiding
  • Inheritance
  • Polymorphism

Classes and Objects

The basic building blocks of object-oriented programming are the class and the object. A class defines the available characteristics and behaviour of a set of similar objects and is defined by a programmer in code. A class is an abstract definition that is made concrete at run-time when objects based upon the class are instantiated and take on the class' behaviour.

Abstraction

Abstraction is the ability to generalize an object as a data type that has a specific set of characteristics and is able to perform a set of actions.
Object-oriented languages provide abstraction via classes. Classes define the properties and methods of an object type.
Examples:

  • For na examaple You can create an abstraction of a person with some characteristics, such as color, height, and weight, name and actions such as talk, sleep and walk. In the C# the characteristics of object are called properties, and the actions are called methods.
  • Object is an abstract representation of a set of data.

Encapsulation

Encapsulation,also known as data hiding, is an important object-oriented programming concept. It is the act of concealing the functionality of a class so that the internal operations are hidden, and irrelevant, to the programmer. With correct encapsulation, the developer does not need to understand how the class actually operates in order to communicate with it via its publicly available methods and properties; known as its public interface.

Encapsulation is essential to creating maintainable object-oriented programs. When the interaction with an object uses only the publicly available interface of methods and properties, the class of the object becomes a correctly isolated unit. This unit can then be replaced independently to fix bugs, to change internal behaviour or to improve functionality or performance.

Passing Messages

Message passing, also known as interfacing, describes the communication between objects using their public interfaces. There are three main ways to pass messages. These are using methods, properties and events. A property can be defined in a class to allow objects of that type to advertise and allow changing of state information. Methods can be provided so that other objects can request a process to be undertaken by an object. Events can be defined that an object can raise in response to an internal action. Other objects can subscribe to these so that they can react to an event occurring.

Abstraction

Objects can work together in many ways within a system. In some situations, classes and objects can be tightly coupled together to provide more complex functionality. This is known as composition. In the car example, the wheels, panels, engine, gearbox, etc. can be thought of as individual classes. To create the car class, you link all of these objects together, possibly adding further functionality. The internal workings of each class are not important due to encapsulation as the communication between the objects is still via passing messages to their public interfaces.

Inheritance

Inheritance is an interesting object-oriented programming concept. It allows one class (the sub-class) to be based upon another and inherit all of its functionality automatically. Additional code may then be added to create a more specialised version of the class.

Some programming languages allow for multiple inheritance where a sub-class is derived from two or more super-classes. C# does not permit this but does allow a class to implement multiple interfaces. An interface defines a contract for the methods and properties of classes that implement it. However, it does not include any actual functionality.

Polymorphism

Polymorphism is the ability for an object to change its behaviour according to how it is being used. Where an object's class inherits from a super-class or implements one or more interfaces, it can be referred to by those class or interface names.

Modularity

In addition to the concepts described above, object-oriented programming also permits increased modularity. Individual classes or groups of linked classes can be thought of as a module of code that can be re-used in many software projects. This reduces the need to redevelop similar functionality and therefore can lower development time and costs.

Posted by Ingenium Web

Ingenium Web

iNGENIUM Ltd. is an software development company from EU which delivers a full range of custom .NET, web and mobile solutions for different business to meet partner's demand.

The Power of Imagination Makes Us Infinite

Related Posts

Comments

comments powered by Disqus