Wednesday 10 September 2014

Object-Oriented Programming

Object-Oriented Programming:

OOP stands for Object-Oriented Programming. OOP is relatively a new way to program computer applications. Before OOP programmers used to creating computer applications using procedural-programming (or structure-programming) but when OOP solved a lot of the problems of the procedural-programming so almost all of the programmers and developers began using OOP languages. In procedural- programming all the program functionality written in a few modules of code or maybe one module (depending on the program) and these modules depend on one another and maybe if you change a line of code you will have to rewrite the whole module again and maybe the whole program but in Object-Oriented Programming programmers write independent parts of a program called classes each class represent a part of the program functionality and these classes can be assembled to form a program and when you need to change some of the program functionality all what you have to do is to replace the target class which may contain a problem. So in OOP applications create by the use of classes and these applications can contain any number of classes.

The Class : Is a building block that contains the properties and functionalities that describe some group of objects

The first thing that you should know about C# programming is that it uses the Class to include the data (in part one, I said that data can be stored in instance variables in the class) and methods to process that data. Think about it in the next example:

    class Test
    {
        public int Add(int x, int y)
        {
            return x + y;
        }
    }

The class Test contains a method called Add (which add to integers and return the result) is a good example for what we are talking about. I said that the Class includes data and there are methods to process that data, here the class test includes the method Add() which takes two integer numbers to add them and this is the functionality of the method. The application that will use the Test class can be something like the following:
    public class Class1
    {
        public Class1()
        {
            Test t1 = new Test();
            Console.WriteLine(t1.Add(5, 4));
        }

    }

The concept of Objects & Classes helps you hide your code implementation from the user of your class. In other words, if you develop a class for your friend to use, he doesn't have to know how you created the methods of that class in order to use it; he'll just need to know how to use it, and what functionality is offered by your class members. The point here is that you don't have to know how another developer developed a certain class; you just have to know how to interface with it. And I said in the first part, when you develop programs with C# you will develop classes.

0 comments:

Post a Comment