This principle of OOP mainly says that whatever be the code (methods, properties, variables etc.) written to develop an app should be wrapped into a container called as CLASS. This helps in providing security to the code which is lacking in procedural languages.
Eg: class Hello
{
..........; //Encapsulated class content
}
2/03/2010 04:26:00 PM |
Category:
OOP in C#
|
I think most of the programmers come from C platform and many others come from other procedural or structural language platforms. After mastering C or any other structural languages, most of us might have thought about the following two major flaws of procedural programming:
-In procedural languages like C we are exposing our piece of code to externals (main() since it is also a user defined function) without setting any permissions. So, there is lack of security (code access security) to the code that we write for procedural languages like C. For example, if we are defining a function in C, there is no restriction to call that function at any point of time under main().
-In procedural languages like C we can define 'n' number of functions under a given program (say one.C). Now suppose that we are developing another program that should contain similar functions which are defined under one.C and the new program name is two.C. Though the functions defined in one.C are similar to the functions that are to be defined under two.C, we cannot consume these functions of one.C in two.C. So, there is no scope for reusability.
Due to the lack of these two major features code access security and reusability in procedural languages, Object-Oriented Programming (OOP) came into picture.
The problem of code access security is rectified by the concept of ENCAPSULATION in OOP and the problem of reusability is rectified by the concept of INHERITANCE in OOP. The other two major features apart from encapsulation and inheritance are Abstraction and Polymorphism which add some weight to the OOP.
2/02/2010 03:48:00 PM |
Category:
OOP in C#
|
Its quiet simple creating and executing a C# app using VS.NET. I reckon one of the major reasons behind this is its user friendly GUI and the other reasons may be like intellisense, pre-written lines of code, code snippets and so on......
To start writing a C# app we need to do the following:
Open VS.NET-->File menu-->new project-->choosing a template (as if now console app); choosing a framework version we want to work with-->click ok. As soon as we click ok, the created file will be opened and within the file we will find the following:
1.The set of namespaces that are frequently used and that are imported using 'using' statement.
2.Current project's namespace which is created automatically.
3.Current Class under the current project's namespace and a Main() under the current class, which are also created automatically.
So now we can directly write our code for C# app within the Main() of the current class as following: Console.WriteLine("first C# app");
Now we can run the current C# app by using Debug option which will build and then run the C# app. To debug we need to press F5 or ctrl+F5. This will output the result in a console window.
I think its quiet evident how VS.NET makes the development of a .NET app so simple. Instead of writing 8 lines of code we just wrote a single line of code and it (single line of code) can be executed by pressing a single key (F5).
2/01/2010 04:13:00 PM |
Category:
Basic C# Programming...
|