I want to run through every step of creating a very simple object oriented designed solution, very simple in nature, using the Visual Studio (2008) and Visual C# as the platform.  My point is to help my fellow polyglots out there, I am making a series that will help you to go from install, to a working model of an OOP structure, to help familiarize yourself with the enviroment.
I hope to help shed light on what is ultimatly a repition of the same concept of  telling the computer what to do in some organized fashion.  Im going to keep it simple, if you are new to OOP, this is a good example to get a tangable working model of a solution based on objects to work with yourself.  If you are a veteran coder, and a situation brings/forces you to use Visual C# , this will get you rockin and rolling so you can compare and contrast aginst your paradim, all at once, syntax, IDE, organization, ect. 
And finally, if you are a polyglot looking to assimulate another enviroment, this is a part of a series, this example is repeated over and over, my digital Rosetta Stone for computer science, if you will.

The example object model: The object set we are creating is going to use encryption as its central theme.  We want to create a situation where one object manages other objects that are based on a particular object.  Fortunatly this comes with pictures:

The Base Class Structure of our Encryption Logic Class.  This is what will allow us the commonality to build aginst.
The Base Class Structure of our Encryption Logic Class. This is what will allow us the commonality to build aginst.
The SecureDataClass, this object utilizes objects based on CryptionLogiBaseClass to provide a unified interface.
The SecureDataClass, this object utilizes objects based on CryptionLogiBaseClass to provide a unified interface.




Prerequisits: The assumption is that you have Visual Studio 2008 installed and operational.  One way to test for operation is simply to build an empty Visual C# application, and execute.  If all things are well an empty form should apear.  Close form and all files, you are ready to begin.

 Step 1: Start Visual Studio, create a new project and add some components to help test our objects.

In the New Project Dialog, Select Windows under Visual C# project types, then select Windows Form Application.  Set the name, location and solution name and click the OK button.
In the New Project Dialog, Select Windows under Visual C# project types, then select Windows Form Application. Set the name, location and solution name:(In this example, the Name of the Application is EncryptionTestApp, the location of the project folder will be C:\ClassesExample and the solution name will be the same as the application name, EncryptionTestApp) and finally click the OK button.
A new form is shown in the IDE, place a TextBox control onto the form and set the Text property to blank and the Name property to textBoxInput.
A new form is shown in the IDE, place a TextBox control onto the form and set the Text property to blank and the Name property to textBoxInput.
Select a Label to place on the form and set its Text property to 'Enter Text'.
Select a Label to place on the form and set its Text property to ‘Enter Text’
Select another Label, and place below the TextBox and Set its style to Fixed3D and change the name to labelOutput.
Select another Label, and place below the TextBox and Set its style to Fixed3D and change the Name to labelOutput.
Place a button onto the Form and set its Text property to 'Go!'
Place a button onto the Form and set its Text property to ‘Go!’

Step 2: Adding the three classes.

Add a new class to the project. This will be done three times, once for each class: CryptionLogiBaseClass, MyFakeLogiClass and SecureDataClass.
Add a new class to the project. This will be done three times, once for each class: CryptionLogiBaseClass, MyFakeLogiClass and SecureDataClass.
Create a new Class and enter a name for the source file. The name is SecureDataClass.cs  Afterward, click the Add button.
Create a new Class and enter a name for the source file. The name is SecureDataClass.cs  Afterward, click the Add button.
Create a new Class as before and enter a name for the source file. The name is CryptionLogicBaseClass.cs  Afterward, click the Add button.
Create a new Class as before and enter a name for the source file. The name is CryptionLogicBaseClass.cs  Afterward, click the Add button.
Create a new Class as before and enter a name for the source file. The Name is MyFakeLogiClass.cs Now click the Add button.
Create a new Class as before and enter a name for the source file. The Name is MyFakeLogiClass.cs Now click the Add button.

Step 3: Defining the three classes

Enter in the source that will define the class.  This provides the base names for all inherited classes to fulfill.
Click the tab CryptionLobiBaseClass. Enter in the source that will define the class. This provides the base names for all inherited classes to fulfill.

-Code Snip-

public abstract class CryptionLogiBaseClass
{
     string Key;
     public CryptionLogiBaseClass(string NewKey)  { Key = NewKey; }
     public string Encrypt()  { return ""; }
     string Value;
}

Select the tab MyFakeLogiClass. Enter in the source that will define the process logic.
Select the tab MyFakeLogiClass. Enter in the source that will define the process logic.

-Code Snip-

public class MyFakeLogiClass:CryptionLogiBaseClass
{
     public MyFakeLogiClass(string KeyValue) : base(KeyValue) { }
     public new string Encrypt()
     {
                string ReturnValue="";
                for (int x=Value.Length-1;x>=0;--x)
                      ReturnVal += Value[x];
                 return ReturnVal;
     }
     public new string Decrypt()
     {
         //Circular Logic so same routine
         return Encrypt();
     }
}

Select the SecureDataClass tab.  Enter in the source that will define and implement the class.
Select the SecureDataClass tab. Enter in the source that will define and implement the class.

-Code Snip-

public class SecureDataClass
{
     public string Encrypt(string Value)
     {
          MyFakeLogiClass ALogi =  new MyFakeLogiClass("TestKEY");
          ALogi.Value = Value;
         return ALogi.Encrypt();
     }
}

Double click the Go button to enter the source that utilizes our objects.
Double click the Go button to enter the source that utilizes our objects

-Code Snip-

private void button1_Click(object sender,EventArgs e)
{        
     SecureDataClass LockIt= new SecureDataClass();          
     labelOutput.Text=LockIt.Encrypt(textBoxInput.Text);    
}

Step 4: Running and testing the Objects.

 

Build and Run the program, do this by clicking the green 'Play' arrow, in the tool bar just below the main menu.
Build and Run the program, do this by clicking the green

 

Example screen shot of the application.
Example screen shot of the application.

You should be able to type into the TextBox a simple sentence, and hit the Go button, and have the answer displayed.  All the real processing is all in the object and not in the hosting application (form object in this case)

 

Thats it, we implemented the basic object model. It is done from the Visual Studio Context, and uses Visual C# as the implementing language.  Hope this gives a good basic layout for you to digest and start you on your way to OOP developed solutions and a better understanding of coding.

9 Responses to “An elementary class design from a Visual C# context”

  1. MacKsTa says:

    Great Work! This works and compiles fine. Keep up the good work!

  2. Reina says:

    You write very well.

  3. alex says:

    Add to my Bookmarks ;)

  4. Den indingaccully says:

    First of all congratulation for such a great site. I learned a lot reading article here today. I will make sure i visit this site once a day so i can learn more.

  5. Halq al Zawiya Shirba says:

    Thank you very much - these look great!

  6. Alex_MAG says:

    Nice work! I’ll have to do a cross post on this one ;)

  7. Pereperaliz says:

    Hello, I can’t understand how to add your blog ( ciscogarcia.com ) in my rss reader
    ————————
    ads: http://qugor.ru

  8. Adurdyperge says:

    ciscogarcia.com - now in my rss reader)))
    ————————
    internet signature: http://youraudiovox.com/music52/map.html

  9. KonstantinMiller says:

    Hi! I like your srticle and I would like very much to read some more information on this issue. Will you post some more?

Leave a Reply