Separating business logic from UI

M

Meya-awe

I have a couple of questions, hopefully someone has come across this
before and can help me. (1) What are the various ways i could separate
my apps UI from business logic - could you provide bare bone example?
(2)I am using a third party supplier library and one of the requirements
is to be able for the app to have the capability to plug in various 3rd
party supplier libaries. i.e. if we go with company X, later when
company Y has a similar product, we can do minimal or no changes and use
the company Y's library instead of the one from company X.

I know these two question may somewhat be related. I appreciate any help
you could provide.
thanks,
BRAMOIN
 
G

Guest

Hi,

I assume your supplier library is one on UI. If yes, then the following
might answer your question. If no, then please tell me what they are used for.

I usually follow this approach:
1. I define business 'Model' classes. These classes would represent biz
entities.
2. The presentation tier would bind only to such Model instances and their
properties
3. the business layer would provide the UI the model instances

Since the UI knows only about models, inner details are abstracted.
 
M

Meya-awe

My supplier library provideds some of the computation necessary in the
business logic.
I am using C#. The problem i have is not understanding the concept but
it is the implementation. That is why i need to look at examples. It
would be good if you could point me to material which provide not only
an example but also an explanation of what is happening.
thanks,
BRAMOIN
 
T

Tasos Vogiatzoglou

1. For the library independance part

You could create an interface that wraps the library's provided
functionality, that declares methods that you are going to need. You
may also have to create objects that support this functionality. Then
you can create implementations of this interface with any library. e.g.
for an application that returns Customers

// the interface declaring the needed methods
public interface ICustomerProvider
{
Customer GetCustomer(int customerID);
}

public class Customer
{
public string CustomerName;
}

/// Implementation of the interface for XCompany library
public class CompanyXCustomerProvider:ICustomerProvider
{

private XCompanyLib_instance;
public CompanyXCustomerProvider(XCompanyLiblibInstance)
{
_instance = libInstance;
}

public Customer GetCustomer(int customerID)
{
CompanyXCustomer customer = _instance.GetCustomer(customerID);
Customer retCust = new Customer();
retCust.CustomerName = customer.Name;
return customer;
}
}

You can create a Factory for these implementation classes, sealing your
code totally from them ... something like :

public class CustomerProviderFactory
{
private CustomerProviderFactory()
{
//private because we do not need to instanciate the class
}
public ICustomerProvider GetProvider(string company)
{
//based on a key pick the appropriate library
if (company.Equals("XCompany"))
{
return XCompanyCustomerProvider(new XCompanyLib());
}
}
}



2. For the UI/Business Logic problem, .NET provides a pretty good model
of seperation with ASP.NET and COM+. You should check the
documentation.

The posted code is not tested or even compiled... it's just an
expression :)

Tasos
 

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