
In the OOP (Oject Oriented Programming) architecture a Class is a collection of variables (properties) and functions (methods) that operates on that data.
An API (Application Program Interface) like the .NET Framework has many prefab Classes to do many things.
Imagine, by example, that we have a Class whose name is Circle having the properties:
color
centerX - for position of the circle in the monitor screen
centerY
radius
and the methods:
area() - returns a number
show() - to draw the circle in the monitor screen
To use this Class inside a program, inside an application, we will need first to create a new object (a prefix having any name - we choose: myC) of the Class, writing a line of code like:
Circle myC = new Circle();
We will need also to set the values for the properties (some can have default values):
myC.color="red";
myC.centerX = 10;
myC.centerY = 10;
myC.radius = 7;
and to use the method to draw the circle:
myC.Show();
Running the program (OK, its not so simple - we will see how to create real programs soon) we will see in the monitor the circle:
If we think that will be useful for us, we can create a variation of this Class. We can extend a Class creating a subclass having new members.
By example, imagine that we would like to create many circles of many sizes and colors having all of then a little blue square in the center. We can define a new Class extending the Class Circle:
class CircleWithLittleBlueSquare: Circle
and inside the "definition" of this subclass (we will see how to do this soon) we can put an object of another prefab Class: Square. And to set values for properties of this new object:
class CircleWithLittleBlueSquare: Circle{
Square myRedS = new Square();
myRedS.Color= "blue";
myRedS.CenterX = this.CenterX;
myRedS.CenterY = this.CenterX;
myRedS.Side = 1.5;
myRedS.Show();
...
Having done this definition we can use this new Class at our application. Something like (OK, a little more complicated than):
CircleWithLittleBlueSquare myCWBS = new CircleWithLittleBlueSquare();
myCWBS.color="green";
myCWBS.centerX = 12;
myCWBS.centerY = 12;
myCWBS.radius = 10;
myCWBS.Show() = 10;
The new Class CircleWithLittleBlueSquare inherits all the members (properties and methods) of the Class Circle, that we have used here. And we will have:
Some Classes (ex: Rectangle, Window) define graphics objects that we can see. Some define abstract things (ex: Timer, Application).
At the new Microsoft WPF (Windows Presentation Fundation) architecture a minimum application that can be executed is the extentions of two Classes of the API available:
Application Window
Something like (OK, a little more complicated than):
class MyApp: Application
class Window1: Window
We need to create an object of the this second Class inside the definition of the first:
class MyApp:Application{
Window1 mainWindow = new Window1();
mainWindow.Show();
...
We will see how to do this in details soon.
When we run the executable (a .EXE file) of a compiled WPF application, an object of the new Class MyApp is created. This starts everything.
NEXT LESSON T.CONTENTS HOMEPAGE
