Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UI on one side and the business code on the other side 1

Status
Not open for further replies.

jabw

Technical User
Apr 30, 2003
103
NL
Just trying to get some things straight.
I don't want to end up with some ravioli code so I want to get it straigt from the start.
This is what I want:

A project called CH7_9 has two cs files one called Form1.cs and the other RWDLog.cs

The From1.cs hold all things related to the UI such as the Form, buttons etc. and RWDLog.cs holds the code related to whatever it should do. It this case it should read,write or delete logging entry's in the eventlogs of windows(but that's not the issue).


How to organize this.???
I'm getting lost in private, public, methods, classes and CH7_9.Form1.x?!....
I think (know) it has to do with things like scope, accessibility of classes etc. but I can't find a decent text, including an example, that explains to me how to go about with this.
How to separate the UserInterface part from the business code part.


Any suggestions?

 
A very quick and simple example:

Include your RWDLog class inside a namespace, and make it public e.g.:

applayercode.cs
Code:
namespace RWD.AppLayer
{
  public class RWDLog 
  {
     public SomeMethod()
     {
        //some code here...
     }
  }
}

then in your form, include the namespace e.g.:

Code:
using RWDAL = RWD.AppLayer;  // with alias 'RWDAL'
or just..
using RWD.AppLayer;  // without alias

you should then have access to the classes therein e.g.:

Code:
 RWDAL.RWDLog myLog = new RWDAL.RWDLog();
 myLog.SomeMethod(); //run a method

Namespaces can span multiple files (classes can too, but that requires the partial modifier and isn't really necessary for you at the moment). And you can nest namespaces as you can with Classes.

I expect that the bits you're missing are the 'using' directive and the namespace, but you don't show us any code so it's hard to tell.

Also, google will help you find a whole raft of examples far more in depth than this. for example: but there's a lot more, so have a browse.

A smile is worth a thousand kind words. So smile, it's easy! :)
 
It looks so obvious but the books I have on C# didn't make it clear.
It also has to do with an object way of thinking.

So it's:
- Path to the code by the using statement.
- make an object with the new statement.
- and then just use it.

I'm stil learning.


Thanks.


 

We're all still learning jabw - regardless of how much we know ;-)

Definitely browse through some of the reference sites for C# and consider Google your best friend - once you become more familiar with the terminology you will find it an invaluable source of answers to your problems (second only to TekTips of course;-) )

Anyway, good luck with your project.


A smile is worth a thousand kind words. So smile, it's easy! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top