3-tier layers

D

Dan Aldean

Hello,

I try to understand how the business and presentation layers would
practically
translate into programming reality.
I read lots of articles about 3-tier, but none of them gave a practical
example
and I managed to understand the data layer only.
Is for example web services and their consumption an instance of n-tier,
covering the business and presentation layers?
If it is not necessary a WEB development how would the presentation and
business
layer come to life, through what? Is ASP the presentation layer and C# the
business layer?

Thanks a lot.
 
K

Kevin Spencer

The 3-tier model is based upon separation of general functionality. You have
3 tiers:

Interface
Business
Data

Each tier is more specific than the one below.

The Data Tier is only for working with underlying data stores. It knows
nothing of specific business rules about how to handle the data. It only
knows how to fetch it, change it, delete it, that sort of thing. It is a
programming interface to the data that any application stores. As such, it
is agnostic of any rules concerning what the data is, or how it is to be
treated. It is the "supply clerk" of the organization. This way it can be
used by many applications.

The Business Tier is for manipulating the data. It contains the Business
logic and Business rules that comprise the "engine" of an application. It
knows everything about the Data Tier, while the Data Tier knows nothing
about the Business Tier. The Business Tier works with Data, but does nothing
to expose it to a user. It does expose what is necessary for any other
component or application to be able to work with the data, and is in charge
of making sure that everything is handled according to the Business rules.
It has a programming interface, but no user interface. This way, the
functionality of the Business tier can be used in many different types of
interfaces.

The User Interface is the most specific. It knows nothing about the Data
Tier; that is the Business Tier's job. It knows everything about the exposed
API of the Business tier, and its job is to present the data to the user,
and to take input from the User and relay it to the Business Tier. It is a
"universal translator" for the application, which speaks human at one end,
and business API at the other.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
A

Andy

I'd add that each tier should be allowed to be physically seperated as
well. All the tiers can operate on seperate servers / workstations.
 
D

Dan Aldean

Thanks for replying,
I was looking more for a description of how the business layer can be
expressed: a DLL,
a COM object, a WEB service?
Theoretically I understand the concept, but the practical side is difficult
for me to grab.
As I see it WEB services would solve the business layer, but what's used
when the application is Windows based?
 
K

Kevin Spencer

A Web Service is an interface. It is a form of presentation tier. It exposes
the API of a set of business classes. A Business tier is a set of classes. A
DLL is a container for code. A COM object isn't even .Net. A Data Tier is
also a set of classes. The classes can reside in one or more assemblies. An
assembly is stored in one or more DLLs.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
D

Dan Aldean

Thanks Kevin,
Couldn't be a WEB service considered a business layer as long as it is a
class with different methods and the application that makes a reference
becomes a presentation layer?
I can create a service on a separate server for example, where I can put all
the business logic in it, but it does not have a presentation until I create
an application on another server (that makes a reference to the service)
which uses controls for the user input.
 
K

Kevin Spencer

If you put your business logic into a Web Service, you have bound the API
for that business logic to a Web Service interface. The Web Service itself
is an interface, but not a programming interface, strictly. Not a good idea,
since there is latency involved, and severe restrictions on the interface
itself. Everything passed through it must be serialized as XML.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
A

Andy

The business layer is usually just an assembly dll used directly. If
you have functionality of the business layer you need to expose to
untrusted sources (such as partner companies, etc), you usually build a
facade layer to communicate with the business layer. The facade layer
could be a web service.

A web service should not be the business layer though; the web service
should be just another 'UI' to the business layer. that way you could
use the business layer in a windows forms application (and wouldn't
need to go throuh a web service).
 
A

Andy

A web service is more of a service and the contract shouldn't change
much.

If you build a business layer as a web service and then need to change
the business object model, you'll force everyone that consumes your web
service to update thier code. The web service should just be an
interface to the business objects. That way your web services don't
necessarly need to change if you change the business logic.
 
D

Dan Aldean

So the solution is to create Class Library projects to keep the business
layer?
Sorry, I am new to C# too.
 
K

Kevin Spencer

Yes, business classes would be in class libraries.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
A

Andy

Yup.

There's a great book which builds a framework for business objects to
help promote proper seperation of tiers.

Pick up a copy of Expert C# 2005 Business Objects by Rockford Lhotka,
published by APress.

HTH
Andy
 
D

Dan Aldean

Thanks.
I just created a shared assembly in a Class Library.
I used the sn -k obj\release\MyShared.snk to create a signature.
Then I used the MyShared.snk in the AssemblyInfo.cs file, in the
[assembly: AssemblyKeyFile("MyShared.snk ")]

section. Then I Rebuilt the solution. Next step was to install the assembly
using

gacutil /i MyShared.dll.



What would be next? I tried to create another project and then use the
reference to

find the MyShared.dll in there but it isn't. What did I do wrong?
 
K

Kevin Spencer

Well, to start with, you didn't need to create a shared assembly. You didn't
need to create a Strong Name for the assembly. You didn't need to install it
in the GAC.

Create a project for your business class library. Don't change any settings,
just use the default template that Visual Studio provides. It is the default
because it is the typical way that class libaries are made. When you need to
use the Business class in another project, add the project to that solution.
You can add the same project to any number of solutions. Then create a
reference to the project is the other project. Bob's your uncle.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

Dan Aldean said:
Thanks.
I just created a shared assembly in a Class Library.
I used the sn -k obj\release\MyShared.snk to create a signature.
Then I used the MyShared.snk in the AssemblyInfo.cs file, in the
[assembly: AssemblyKeyFile("MyShared.snk ")]

section. Then I Rebuilt the solution. Next step was to install the
assembly using

gacutil /i MyShared.dll.



What would be next? I tried to create another project and then use the
reference to

find the MyShared.dll in there but it isn't. What did I do wrong?



Kevin Spencer said:
Yes, business classes would be in class libraries.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
D

Dan Aldean

Thanks a lot
When do I need it in GAC?

Kevin Spencer said:
Well, to start with, you didn't need to create a shared assembly. You
didn't need to create a Strong Name for the assembly. You didn't need to
install it in the GAC.

Create a project for your business class library. Don't change any
settings, just use the default template that Visual Studio provides. It is
the default because it is the typical way that class libaries are made.
When you need to use the Business class in another project, add the
project to that solution. You can add the same project to any number of
solutions. Then create a reference to the project is the other project.
Bob's your uncle.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

Dan Aldean said:
Thanks.
I just created a shared assembly in a Class Library.
I used the sn -k obj\release\MyShared.snk to create a signature.
Then I used the MyShared.snk in the AssemblyInfo.cs file, in the
[assembly: AssemblyKeyFile("MyShared.snk ")]

section. Then I Rebuilt the solution. Next step was to install the
assembly using

gacutil /i MyShared.dll.



What would be next? I tried to create another project and then use the
reference to

find the MyShared.dll in there but it isn't. What did I do wrong?



Kevin Spencer said:
Yes, business classes would be in class libraries.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

So the solution is to create Class Library projects to keep the
business layer?
Sorry, I am new to C# too.

If you put your business logic into a Web Service, you have bound the
API for that business logic to a Web Service interface. The Web
Service itself is an interface, but not a programming interface,
strictly. Not a good idea, since there is latency involved, and severe
restrictions on the interface itself. Everything passed through it
must be serialized as XML.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

Thanks Kevin,
Couldn't be a WEB service considered a business layer as long as it
is a class with different methods and the application that makes a
reference becomes a presentation layer?
I can create a service on a separate server for example, where I can
put all the business logic in it, but it does not have a presentation
until I create an application on another server (that makes a
reference to the service) which uses controls for the user input.


A Web Service is an interface. It is a form of presentation tier. It
exposes the API of a set of business classes. A Business tier is a
set of classes. A DLL is a container for code. A COM object isn't
even .Net. A Data Tier is also a set of classes. The classes can
reside in one or more assemblies. An assembly is stored in one or
more DLLs.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

Thanks for replying,
I was looking more for a description of how the business layer can
be expressed: a DLL,
a COM object, a WEB service?
Theoretically I understand the concept, but the practical side is
difficult for me to grab.
As I see it WEB services would solve the business layer, but what's
used when the application is Windows based?

The 3-tier model is based upon separation of general
functionality. You have 3 tiers:

Interface
Business
Data

Each tier is more specific than the one below.

The Data Tier is only for working with underlying data stores. It
knows nothing of specific business rules about how to handle the
data. It only knows how to fetch it, change it, delete it, that
sort of thing. It is a programming interface to the data that any
application stores. As such, it is agnostic of any rules
concerning what the data is, or how it is to be treated. It is the
"supply clerk" of the organization. This way it can be used by
many applications.

The Business Tier is for manipulating the data. It contains the
Business logic and Business rules that comprise the "engine" of an
application. It knows everything about the Data Tier, while the
Data Tier knows nothing about the Business Tier. The Business Tier
works with Data, but does nothing to expose it to a user. It does
expose what is necessary for any other component or application to
be able to work with the data, and is in charge of making sure
that everything is handled according to the Business rules. It has
a programming interface, but no user interface. This way, the
functionality of the Business tier can be used in many different
types of interfaces.

The User Interface is the most specific. It knows nothing about
the Data Tier; that is the Business Tier's job. It knows
everything about the exposed API of the Business tier, and its job
is to present the data to the user, and to take input from the
User and relay it to the Business Tier. It is a "universal
translator" for the application, which speaks human at one end,
and business API at the other.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

Hello,

I try to understand how the business and presentation layers
would practically
translate into programming reality.
I read lots of articles about 3-tier, but none of them gave a
practical example
and I managed to understand the data layer only.
Is for example web services and their consumption an instance of
n-tier,
covering the business and presentation layers?
If it is not necessary a WEB development how would the
presentation and business
layer come to life, through what? Is ASP the presentation layer
and C# the business layer?

Thanks a lot.
 
A

Andy

Most likely never. The GAC is really for assemblies that would be
shared across many applications.

I'd say just pretend installing to the GAC isn't even an option. Thats
the standard way to use libraries.
 
D

Dan Aldean

Thanks Andy.
In my situation when I registered my class in GAC, how can I make it visible
to another application?
 
K

Kevin Spencer

That would be done by modifying the system registry.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 

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