
We said that the the OOP (Oject Oriented Programming) architecture has the concept of Class. The .NET architecture is a little more complicated. A Class is only one of the Types we have.
There are two main Types:
Value-types are:
The usual predefined primitives are:
Reference-types are:
A Class defines and inplements its members:
The .NET Framework API has many prefab Classes. The Class: Object is the base of all the other Classes.
A Class (prefab or a subclass defined by ourselves - a subclass is also a Class!) is placed logically inside a namespace.
To define a subclass whose name will be CircleWithLittleBlueSquare we will write, by example:
namespace myFigures{
class CircleWithLittleBlueSquare: Circle{
//definition of the class
}
}
Usually, phisically a namespace is inside a library, a .DLL file, to be reused in many applications (MyFigures.dll, by example). But we can define a namespace for the subclasses of an executable EXE file (that will be valid and used only at this executable application).
A .DLL file can have sometimes many namespaces.
To use members of a Class we need to create an "instance" (a copy) of this Class in the memory of the computer. This instance will have a name and we can, at our application, access this instance using this name like a prefix, followed by a dot and the designation of the member:
... CircleWithLittleBlueSquare myCWS = new CircleWithLittleBlueSquare(); myCWS.Color="blue"; ...
It's usual to call this instance and/or this name or this prefix by the word: object. The object of the Class CircleWithLittleBlueSquare is myCWS. It's usual to say something like: "The color of myCWS is blue".
An object this can be used inside a Class to designate an instance of this class. Like we saw at:
class CircleWithLittleBlueSquare: Circle{
Square myRedS = new Square();
myRedS.Color= "blue";
myRedS.CenterX = this.CenterX;
myRedS.CenterY = this.CenterX;
...
meaning that the center of myRedS will be the same of that defined for an object of CircleWithLittleBlueSquare.
Inside a Class, a method having the same name of the Class is a constructor and it will run automaticaly when an instance of the Class is created.
At a subclass we can have a new implementation of a method that exists at the base Class. It needs to have the word ( a modifier): virtual before its definition at the base Class. At the subclass it will have the modifier: override. If we would like to execute the basic method inside another at the subclass having an overrided , we need to use the prefix base before its name.
By default a method is not virtual and can be not "overrided".
We can have (or to create) many methods having the same name but having different parameters. We call this "overload" of a method. Like how we define the parameters, whem using it, one of these methods will be used.
Properties and fields that can not accept different values have the modifier: const.
A Class having the modifier: sealed can't have subclasses.
A member having the modifier static will have only one instantialization even if we have created many instantializations of its Class. If we modify its value (beeing a property) inside an object, this value will be modofied at another object of the same class in the memory!
A method can have the modifier synchronized. When we execute it, there will be a lock of the object and nothing can be modified at this object until we finish the execution of the method. This is important if we work using threads. We will talk about threads in the future.
Now something about accessibility.
A member can have one of the modifiers:
The default accessibility is: private.
A Class is partial if defined inside two files: a .XAML file and a .XAML.CS file.
WOW! Lots of information! At the next lesson we will begin the "real thing"...
PREVIOUS LESSON NEXT LESSON T.CONTENTS HOMEPAGE
