An elementary class design from a Visual C# context
Posted by: Cisco in Computers, SoftwareThe 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:
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:(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.
Step 2: Adding the three classes.
Step 3: Defining the three classes
-Code Snip-
public abstract class CryptionLogiBaseClass
{
string Key;
public CryptionLogiBaseClass(string NewKey) { Key = NewKey; }
public string Encrypt() { return ""; }
string Value;
}
-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();
}
}
-Code Snip-
public class SecureDataClass
{
public string Encrypt(string Value)
{
MyFakeLogiClass ALogi = new MyFakeLogiClass("TestKEY");
ALogi.Value = Value;
return ALogi.Encrypt();
}
}
-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.
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.


Select from the menu bar, File -> New -> Project














Entries (RSS)
August 11th, 2008 at 8:55 pm
Great Work! This works and compiles fine. Keep up the good work!
October 29th, 2008 at 10:29 am
You write very well.
December 9th, 2008 at 11:07 pm
Add to my Bookmarks
December 18th, 2008 at 8:49 am
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.
February 6th, 2009 at 8:06 am
Thank you very much - these look great!
February 7th, 2009 at 1:09 am
Nice work! I’ll have to do a cross post on this one
February 7th, 2009 at 4:33 am
Hello, I can’t understand how to add your blog ( ciscogarcia.com ) in my rss reader
————————
ads: http://qugor.ru
February 7th, 2009 at 7:16 am
ciscogarcia.com - now in my rss reader)))
————————
internet signature: http://youraudiovox.com/music52/map.html
July 6th, 2009 at 5:25 pm
Hi! I like your srticle and I would like very much to read some more information on this issue. Will you post some more?