I
iTISTIC
Developing a new app and am trying to make this my first truly
OOP/3-Tier app. I understand the principles of the presentation,
business, and data layers. I do, however, have some questions on where
certain functionality should be placed and how some things should be
implemented.
Let's use a simple example such as an application to manage customer
records (customer_id, first_name, last_name). I'd have a Customer
business object with ID, FirstName, and LastName properties. What I
don't understand is the following:
1. How do I obtain a Customer business object pre-loaded with data from
the database (customer_id 3 for example). I could create a constructor
in the Customer business class with the customer_id as a parameter and
have the constructor call the data layer to return a dataset containing
the customer's data and then set the properties accordingly. Is this
how this is normally accomplished? I could also have a method in the
Customer data layer that accepts a customer_id as a parameter and
returns a Customer business object. My only problem with this is that I
have it in my head that the presentation layer should never communicate
with the data layer. Some help here would be great.
2. How do I obtain a collection or ArrayList of Customer objects in the
case where I need to return more than one customer object? Such an
example would be a form that listed all customers. Calling a method in
the Customer data layer to return an ArrayList of Customer business
objects would work here as well, but this is breaking the same rule of
having the presentation layer working with the data layer. The other
option is to put a method in the Customer business object to return an
ArrayList of Customer business objects, but then my code has to
instantiate the Customer object simply to return more Customer objects.
This is unless I make the method in the Customer business object
shared.
3. Data layer methods to insert, update, delete database records -
Should the insert and update methods accept business objects as
parameters or should they accept a long parameter list that contains a
seperate parameter for each of the business object's properties?
Any help anyone can provide here is more than welcome. These issues
have been keeping me from developing an OOP/3-tier solution for quite
some time as I just can't seem to force myself to develop a system
without truly knowing how these issues should be tackled the proper
way.
Thanks in advance for your help!
Shawn Berg
OOP/3-Tier app. I understand the principles of the presentation,
business, and data layers. I do, however, have some questions on where
certain functionality should be placed and how some things should be
implemented.
Let's use a simple example such as an application to manage customer
records (customer_id, first_name, last_name). I'd have a Customer
business object with ID, FirstName, and LastName properties. What I
don't understand is the following:
1. How do I obtain a Customer business object pre-loaded with data from
the database (customer_id 3 for example). I could create a constructor
in the Customer business class with the customer_id as a parameter and
have the constructor call the data layer to return a dataset containing
the customer's data and then set the properties accordingly. Is this
how this is normally accomplished? I could also have a method in the
Customer data layer that accepts a customer_id as a parameter and
returns a Customer business object. My only problem with this is that I
have it in my head that the presentation layer should never communicate
with the data layer. Some help here would be great.
2. How do I obtain a collection or ArrayList of Customer objects in the
case where I need to return more than one customer object? Such an
example would be a form that listed all customers. Calling a method in
the Customer data layer to return an ArrayList of Customer business
objects would work here as well, but this is breaking the same rule of
having the presentation layer working with the data layer. The other
option is to put a method in the Customer business object to return an
ArrayList of Customer business objects, but then my code has to
instantiate the Customer object simply to return more Customer objects.
This is unless I make the method in the Customer business object
shared.
3. Data layer methods to insert, update, delete database records -
Should the insert and update methods accept business objects as
parameters or should they accept a long parameter list that contains a
seperate parameter for each of the business object's properties?
Any help anyone can provide here is more than welcome. These issues
have been keeping me from developing an OOP/3-tier solution for quite
some time as I just can't seem to force myself to develop a system
without truly knowing how these issues should be tackled the proper
way.
Thanks in advance for your help!
Shawn Berg