Computers & Accessories: Buy Computers & Accessories Online

Search Latest Price in

Breaking News

C#- New features Object-Oriented

Print Friendly and PDF

You wouldn't expect a new language to not support object-oriented features, would you? C#, of course, supports all the key object-oriented concepts such as encapsulation, inheritance, and polymorphism. The entire C# class model is built on top of the NGWS runtime's Virtual Object System(VOS), which is described in the next chapter. The object model is part of the infrastructure, and is no longer part of the programming language.

One thing you will notice right from the start is that there are no more global functions, variables, or constants. Everything must be encapsulated inside a class, either as an instance member (accessible via an instance of a class—an object) or a static member (via the type). This makes your C# code more readable and also helps to reduce potential naming conflicts.
The methods you can define on classes are, by default, non virtual (they cannot be overridden by deriving classes). The main point of this is that another source of errors disappears—the accidental overriding of methods. For a method to be able to be overridden, it must have the explicit virtual modifier. This behavior not only reduces the size of the virtual function table, but also guarantees correct versioning behavior.

When you are used to programming classes in C++, you know that you can set different access levels for class members by using access modifiers. C# also supports the private, protected, and public access modifiers, and also adds a fourth one: internal. Details about these access modifiers are presented in  "Classes."
How many of you have ever created a class that derives from multiple base classes? (ATL programmers, your vote doesn't count!) In most cases, you need to derive from only one class. Multiple base classes usually add more problems than they solve. That is why C# allows only one base class. If you feel the need for multiple inheritance, you can implement interfaces.

A question that might come up is how to emulate function pointers when there are no pointers in C#. The answer to this question is delegates, which provide the underpinnings for the NGWS runtime's event model. Again, I have to put off a full explanation until 

No comments