Object-oriented Programming with C#


© Jose Aniceto

In our quest to write better software, the programming community discovered that object-oriented programming bring many benefits that allow us to develop bug-free software. Mind you, we are far from achieving this goal, but object-oriented programming is definitely the right step towards it.

There are many object-oriented languages out in the market. Programming languages like Java, C++, Smalltalk and Eiffel all offer different implementations of object-oriented approach to programming. The shortcomings of C++ came from a design goal that the language should be compatible with C. Hence it has many of C's shortcomings.

C# on the other hand was designed from scratch and with a view of a common operating environment, which is the .Net platform. C# addresses some of the common problems plaguing C++ developers and class designers.

C# is an object-oriented programming language and is a good language to use for beginners wanting to learning the concepts of object-orientation. To qualify as an object-oriented language, there are three main concepts that a programming language must support - Abstraction, Inheritance and Encapsulation.

Abstraction is the ability of a programming language to define internal types and be able to control external access to the types. C# has similar abstraction technique to Java and C++. Listing 1 is an example of a class that captures essential information about an employee.

Listing 1
class Employee {
// -- Attributes
// --
public int EmployeeID;
public string Name;
public bool Married;
public int Status;
public decimal Salary;
}

Abstraction allows us to model real-world objects by defining their characteristics and attributes. In C, you would represent Listing 1 using struct. However, this as far as you can stretch C's functionality. A common problem among C programmers is that functions are all over the place. It is impossible in C to group functions that relate to particular type.

Encapsulation enables programmers to group actions together with their respective owners. Using our Employee class, we might need a function that would calculate tax based on a given salary. In C, you would write something like Listing 2.

In C#, we can write a function called Tax() and associate it to the Employee class.

Listing 3

Go To Page: 1 2 3


The copyright of the article Object-oriented Programming with C# in C# Programming is owned by . Permission to republish Object-oriented Programming with C# in print or online must be granted by the author in writing.

Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo