How to seperate the business logic from the UI

R

Relaxin

I'm coming from Borland C++ and am "somewhat" new to C#, but very seasoned
in C++.

I'm looking for a specific feature that Borland had that I can't seem to
find in C#.

In Borland that feature is a DataModule.
This is a place where you place all of your Database and business logic.
This logic can then be "bound" to your UI by use of Borland Datasource
components.

This provides a very clean design and clear seperation of UI and data.
It also allow you to use the business logic without the UI if the need
arises.

Does C# offer something like this?

If not, how would you seperate your business logic from the UI?

Thanks
 
W

William Stacey [MVP]

Databinding. For example you can have List<T> containing all your biz
collection or objects. A DataViewGrid, for example can take that List<T> to
display it and update the object(s) in the list.

--
William Stacey [MVP]

| I'm coming from Borland C++ and am "somewhat" new to C#, but very seasoned
| in C++.
|
| I'm looking for a specific feature that Borland had that I can't seem to
| find in C#.
|
| In Borland that feature is a DataModule.
| This is a place where you place all of your Database and business logic.
| This logic can then be "bound" to your UI by use of Borland Datasource
| components.
|
| This provides a very clean design and clear seperation of UI and data.
| It also allow you to use the business logic without the UI if the need
| arises.
|
| Does C# offer something like this?
|
| If not, how would you seperate your business logic from the UI?
|
| Thanks
|
|
|
|
 
R

Russell Mangel

You do this by creating a new Project (class library)
for each layer that you need. If you have 3 layers
then you will need 3 class libraries (3 .dlls).

A typical 3-5 layer application will look like this:

YourApp.Business.dll
YourApp.BusinessEntities.dll
YourApp.DalSql.dll
YourApp.Gui.WinForms.exe
YourApp.Gui.ASPnet.exe

Very clean seperation,
all code for Biz Logic is in Business.dll, etc.
In this case there are two UI programs,
they both can use the supporting .dlls. You
do this by adding a reference to the .dlls
needed in the .exe projects.

As for business entity layer you can
use either datasets *or* custom business
objects (c# classes). Datasets are easier
but classes are much more powerful.

Russell Mangel
Las Vegas, NV

This book is very good, it is slanted towards datasets, but does have
considerable information on Custom Business Objects.
Brian does an excellant job explaining how to build a layered application.

Data Binding with Windows Forms 2.0: Programming Smart Client Data
Applications with .NET (Microsoft Net Development Series)
by Brian Noyes
http://www.amazon.com/Data-Binding-...=pd_bbs_1/103-5295793-5560625?ie=UTF8&s=books

Another good resource for Custom Business Objects is: (no datasets).

Expert C# 2005 Business Objects, Second Edition by Rockford Lhotka
http://www.amazon.com/Expert-2005-B...=pd_bbs_1/103-5295793-5560625?ie=UTF8&s=books
 
T

TheSteph

To separate the Db code from UI code in the designer, you can use "partial
class" (.NET 2.0) to define a new ".cs" file that will contain only your Db
Logic. Partial class is a way to split a class in multiple files.



Example :



File for UI : DbForm1.cs



Partial class DbForm1

{

//..do things

}





File for Db: DbForm1-DB.cs



Partial class DbForm1

{

//..do things

}





Steph.
 
J

Joerg Jooss

Thus wrote TheSteph,
To separate the Db code from UI code in the designer, you can use
"partial class" (.NET 2.0) to define a new ".cs" file that will
contain only your Db Logic. Partial class is a way to split a class
in multiple files.

One should rather design and implement a proper data access layer...
 
R

Relaxin

One should rather design and implement a proper data access layer... --
Uhm..yea, thanks.
Not sure how that answers my question.
 
D

DBC User

Hi,

I am not an expert nor know about Borland Datasource. Here is what I do
in my multi later programming. I use MVP pattern (look at MS pattersn
and practices). Depending on what kind of database you are using, use
ER mapping tool seperate the data layer from data layer and put all
your bussiness login in the upper layer. This is a very clean way to
seprate the the things out for scalability and mantence.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top