473,420 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,420 software developers and data experts.

How to define business object

ad
I have studied buisness layer in
http://beta.asp.net/QUICKSTART/util/...ViewObject.src

It separate Author class to Author and AuthorComponent
If I combine the two together into Author Class for convenience, like
codes below:
Is it ok to do that?

------------Code-------------------------------------------------
public class Author
{
private String _id;

public String ID
{
get
{
return _id;
}

set
{
_id = value;
}
}

private String _name;

public String Name
{
get
{
return _name;
}
set { _name = value; } } private String _lastName;
......

public Author (String id, String name, String lastName, String state)
{
this.ID = id;
this.Name = name;
this.LastName = lastName;
this.State = state;
}

public Author()
{
// default constructor
}

public List<Author> GetAuthorsByState (String state, String
sortExpression)
{
List<Author> authors = new List<Author> ();
DataSet ds = AuthorsDB.GetAuthorsByState (state);

foreach (DataRow row in ds.Tables[0].Rows)
{
authors.Add (new Author ((String)row["au_id"],
(String)row["au_fname"], (String)row["au_lname"], (String)row["state"]));
}

authors.Sort(new AuthorComparer(sortExpression));
return authors;
}

public int UpdateAuthor (string ID, string LastName, string Name, string
State)
{
return AuthorsDB.UpdateAuthor (ID, LastName, Name, State);
}

public int UpdateAuthor(Author a)
{
return AuthorsDB.UpdateAuthor(a.ID, a.LastName, a.Name, a.State);
}

public List<String> GetStates()
{
List<String> states = new List<String>();
DataSet ds = AuthorsDB.GetStates();

foreach (DataRow row in ds.Tables[0].Rows)
{
states.Add((String)row["state"]);
}
return states;
}
}

}
Nov 17 '05 #1
8 1916
"ad" <ad@wfes.tcc.edu.tw> a écrit dans le message de news:
uP**************@TK2MSFTNGP09.phx.gbl...
I have studied buisness layer in
http://beta.asp.net/QUICKSTART/util/.../samples/data/
GridViewObject.src
It separate Author class to Author and AuthorComponent
If I combine the two together into Author Class for convenience, like
codes below:
Is it ok to do that?


This is not a good idea as you are going to be mixing functionality that is
not strictly part of the business object into that class.

IMO, the example is a poor one in the naming of the "AuthorComponent" class.
It is good to separate out the retrieval of a list of States and the
provision of a Comparer class as these don't necessarily belong in the
Author class. The aim of this example is to separate out classes to
accomodate an ASP control scenario, which is not necessarily the best way to
partition classes.

Are you aiming to use ASP or do you want to use the classes in a more
general business scenario ?

Joanna

--
Joanna Carter
Consultant Software Engineer
Nov 17 '05 #2
ad
Thank, I want to use the classes in a more general business scenario.
Could you give me more advice?
"Joanna Carter (TeamB)" <jo*****@nospamforme.com> ¼¶¼g©ó¶l¥ó·s»D
:OZ**************@TK2MSFTNGP14.phx.gbl...
"ad" <ad@wfes.tcc.edu.tw> a écrit dans le message de news:
uP**************@TK2MSFTNGP09.phx.gbl...
I have studied buisness layer in

http://beta.asp.net/QUICKSTART/util/.../samples/data/ GridViewObject.src

It separate Author class to Author and AuthorComponent
If I combine the two together into Author Class for convenience, like
codes below:
Is it ok to do that?
This is not a good idea as you are going to be mixing functionality that

is not strictly part of the business object into that class.

IMO, the example is a poor one in the naming of the "AuthorComponent" class. It is good to separate out the retrieval of a list of States and the
provision of a Comparer class as these don't necessarily belong in the
Author class. The aim of this example is to separate out classes to
accomodate an ASP control scenario, which is not necessarily the best way to partition classes.

Are you aiming to use ASP or do you want to use the classes in a more
general business scenario ?

Joanna

--
Joanna Carter
Consultant Software Engineer

Nov 17 '05 #3
"ad" <ad@wfes.tcc.edu.tw> a écrit dans le message de news:
ea**************@TK2MSFTNGP10.phx.gbl...
Thank, I want to use the classes in a more general business scenario.
Could you give me more advice?


In the example of an Author, I would use the class as it is demonstrated,
but would possibly also add a property which allows access to a list of
Books. But when it comes to retrieving a list of States, this is really not
a part of the Author class, it seems to be just a utility function that
isn't actually used or even necessary.

If you need to get a list of Authors according to which State they live in
then you could consider adding a static method to the Author Class

class Author
{
...

public static List<Author> GetAuthorsByState(string state)
{
AuthorsDB.GetAuthorsByState(state);
}
}.

However, placing code that knows about database functionality means that you
have inextricably tied your business class to using one particular type of
database; something you might want to change later on.

So instead, it is a good idea to develop something known as an OPF (Object
Persistence Framework). Now OPFs can be as simple or as complicated as you
wish, but one way is to use the idea of something like the AuthorComponent
as described in the example.

I would remove the GetStates method from the whole example as it seems to
server no purpose and is not part of the Author class's responsibilities.

But apart from that the idea of the AuthorComponent class is to act as a
mediator so that the Author class need know nothing about getting its own
data, it is just submitted to the AuthorComponent for
storage/retrieval/deletion and it is the Component class that is the only
class that needs to know anything about databases.

Personally, I would change all the methods of the AuthorsComponent class to
be static as there is no state data required.

So then you could rewrite the static GetAuthorsByState method to address the
component class.

class Author
{
...

public static List<Author> GetAuthorsByState(string state)
{
AuthorsComponent.GetAuthorsByState(state);
}
}.

To give you an idea of what a true OPF provides, here is an extract from one
of mine :

class PersistenceBroker
{
public static bool StoreObject(object obj)
{
...
}

public static bool DeleteObject(object obj)
{
...
}

public static T RetrieveObject<T>()
{
...
}

public static List<T> RetrieveList<T>()
{
...
}

public static List<T> RetrieveList<T>(Criteria crit)
{
...
}
}

Now internally, there is a system of class maps that allow me to detect
which type of object has been passed in and to select the appropriate
internal connection for handling instances of that type. The Connection
classes can use SQL, XML, text, or any other means of storage; the trick
being that it doesn't matter what the underlying data mechanism is, each
Connection knows how to do whatever translation is required.

In the example of an SQL Connection, you can either auto-generate the SQL on
the fly or you can create custom translation classes, one for each type to
be stored.

The overriding raison d'être for this level of separation of data from
business classes is the provision of a flexible framework that allows you to
change database without having to change any of your business logic.

Likewise, the Component example you cited also allows us to separate the UI
(in this case ASP) from the business layer; equally important if you want to
write all your business logic only once, regardless of whether you want to
display objects in a WinForms or ASP app.

Take a look at some articles on OPF and MVP on my website for further
information. Then I guess you might have one or two more questions ? :-))

www.carterconsulting.org.uk

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
Nov 17 '05 #4
Please ensure that your system clock is set correctly. People who push to
the head of the queue are generally considered as rude.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
I have studied buisness layer in
http://beta.asp.net/QUICKSTART/util/...ViewObject.src

It separate Author class to Author and AuthorComponent
If I combine the two together into Author Class for convenience, like
codes below:
Is it ok to do that?

------------Code-------------------------------------------------
public class Author
{
private String _id;

public String ID
{
get
{
return _id;
}

set
{
_id = value;
}
}

private String _name;

public String Name
{
get
{
return _name;
}
set { _name = value; } } private String _lastName;
......

public Author (String id, String name, String lastName, String state)
{
this.ID = id;
this.Name = name;
this.LastName = lastName;
this.State = state;
}

public Author()
{
// default constructor
}

public List<Author> GetAuthorsByState (String state, String
sortExpression)
{
List<Author> authors = new List<Author> ();
DataSet ds = AuthorsDB.GetAuthorsByState (state);

foreach (DataRow row in ds.Tables[0].Rows)
{
authors.Add (new Author ((String)row["au_id"],
(String)row["au_fname"], (String)row["au_lname"], (String)row["state"]));
}

authors.Sort(new AuthorComparer(sortExpression));
return authors;
}

public int UpdateAuthor (string ID, string LastName, string Name,
string
State)
{
return AuthorsDB.UpdateAuthor (ID, LastName, Name, State);
}

public int UpdateAuthor(Author a)
{
return AuthorsDB.UpdateAuthor(a.ID, a.LastName, a.Name, a.State);
}

public List<String> GetStates()
{
List<String> states = new List<String>();
DataSet ds = AuthorsDB.GetStates();

foreach (DataRow row in ds.Tables[0].Rows)
{
states.Add((String)row["state"]);
}
return states;
}
}

}

Nov 17 '05 #5
Joanna,

Very interesting that you can write so much sensible comments about so
meaningless a piece of code. However somewhere in your comments I have
to disagree.

Regards,
Rick
On Mon, 13 Jun 2005 13:23:58 +0100, "Joanna Carter \(TeamB\)"
<jo*****@nospamforme.com> wrote:
"ad" <ad@wfes.tcc.edu.tw> a écrit dans le message de news:
ea**************@TK2MSFTNGP10.phx.gbl...
Thank, I want to use the classes in a more general business scenario.
Could you give me more advice?
In the example of an Author, I would use the class as it is demonstrated,
but would possibly also add a property which allows access to a list of
Books. But when it comes to retrieving a list of States, this is really not
a part of the Author class, it seems to be just a utility function that
isn't actually used or even necessary.

If you need to get a list of Authors according to which State they live in
then you could consider adding a static method to the Author Class

class Author
{
...

public static List<Author> GetAuthorsByState(string state)
{
AuthorsDB.GetAuthorsByState(state);
}
}.

However, placing code that knows about database functionality means that you
have inextricably tied your business class to using one particular type of
database; something you might want to change later on.

1) AuthorsDB could be some a data management class which makes Author
independent of every database knowledge.
2) Writing for multiple database support is a much overrated scenario.
80% of the time a program supports 1 database platform for its entire
life.

Joanna


Nov 17 '05 #6
GTi
"Rick Elbers" <ri*********@chello.nl> skrev i melding
news:j7********************************@4ax.com...
Joanna,

Very interesting that you can write so much sensible comments about so
meaningless a piece of code. However somewhere in your comments I have
to disagree.

Regards,
Rick
On Mon, 13 Jun 2005 13:23:58 +0100, "Joanna Carter \(TeamB\)"
<jo*****@nospamforme.com> wrote:
"ad" <ad@wfes.tcc.edu.tw> a écrit dans le message de news:
ea**************@TK2MSFTNGP10.phx.gbl...
Thank, I want to use the classes in a more general business scenario.
Could you give me more advice?
In the example of an Author, I would use the class as it is demonstrated,
but would possibly also add a property which allows access to a list of
Books. But when it comes to retrieving a list of States, this is really
not
a part of the Author class, it seems to be just a utility function that
isn't actually used or even necessary.

If you need to get a list of Authors according to which State they live in
then you could consider adding a static method to the Author Class

class Author
{
...

public static List<Author> GetAuthorsByState(string state)
{
AuthorsDB.GetAuthorsByState(state);
}
}.

However, placing code that knows about database functionality means that
you
have inextricably tied your business class to using one particular type of
database; something you might want to change later on.

1) AuthorsDB could be some a data management class which makes Author
independent of every database knowledge.
2) Writing for multiple database support is a much overrated scenario.
80% of the time a program supports 1 database platform for its entire
life.

Joanna

2) Writing for multiple database support is a much overrated scenario.
80% of the time a program supports 1 database platform for its entire
life.

I agree on that one.
But if you only design the application for that, you will have a huge job
redesigning the whole program if the program must support another engine.
If you have that in mind when designing your program the time you save
is huge if changed to another DB and minor at design time.
Nov 17 '05 #7
"Rick Elbers" <ri*********@chello.nl> a écrit dans le message de news:
j7********************************@4ax.com...
Very interesting that you can write so much sensible comments about so
meaningless a piece of code. However somewhere in your comments I have
to disagree.
Well, I was trying to reinforce the intent of the cited example to separate
business logic from everything else like data storage and UI. But it is a
truly horrible example :-)
1) AuthorsDB could be some a data management class which makes Author
independent of every database knowledge.
2) Writing for multiple database support is a much overrated scenario.
80% of the time a program supports 1 database platform for its entire
life.


As I mentioned I have a much more comprehensive approach to object storage;
reducing such a monster to simple concepts is quite difficult. In fact it is
more difficult to write application code for a simple persistence mechanism
than it is to do so for a more comprehensive one.

You are correct in saying that most applications only ever get to talk to
one type of database, but the design of a good OPF so separates the business
layer from *any* database knowledge that it is simplicity itself to change
DB at will; not the original aim maybe but a very useful side-effect :-)

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
Nov 17 '05 #8
In message <er**************@tk2msftngp13.phx.gbl>, "Joanna Carter
(TeamB)" <jo*****@nospamforme.com> writes
You are correct in saying that most applications only ever get to talk to
one type of database, but the design of a good OPF so separates the business
layer from *any* database knowledge that it is simplicity itself to change
DB at will; not the original aim maybe but a very useful side-effect :-)


Agree entirely, and given that the hard part of the abstraction layer is
done for you (that's what System.Data *is*) there's no real reason not
to implement a separate data access tier.

--
Steve Walker
Nov 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Tim Jarvis | last post by:
Hi, I have an object that I am binding to a text box, this object exposes a boolean field, and I have implemented a format event handler and a parse event handler for the binding object, where I...
25
by: Stuart Hilditch | last post by:
Hi all, I am hoping that someone with some experience developing nTier apps can give me some advice here. I am writing an nTier web app that began with a Data Access Layer (DAL), Business...
0
by: Khuzema | last post by:
Dear All, I am using issue tracker architecture and developed business object for my application. Now, in VS Beta 2, I humbly want to know how i can have same feature as dataset, in my business...
6
by: Nate | last post by:
I am in a slight predicament trying to determine the most efficient and effective way to connect/disconnect from a database within a business object (c# dll). I'm also keeping in mind the concept...
1
by: Nemisis | last post by:
hi guys, Currently converting an old classic asp system to a OOP asp.net application. We are building the new application using a 3 tier arcitecture and i was wondering about the following. ...
2
by: Aryan | last post by:
Hi, I am implementing Business object, but while implementing this I want to have DataTable or DataSet as part of Business Object. For example, I want to bind controls directly to these Business...
3
by: Aryan | last post by:
Hi, I am implementing Business object, but while implementing this I want to have DataTable or DataSet as part of Business Object. For example, I want to bind controls directly to these Business...
25
by: Penelope Dramas | last post by:
Hello, I'm in a front of very serious .net redesign/rewrite of an old VB6 application. I had been asked to make it .NET 2.0 and would like to ask couple of questions regarding data access as...
2
by: Chris Zopers | last post by:
Hello, I would like to know what's the best way to implement a business logic layer between my user interface and my database. I would say I'd make a dll-project for the business logic layer...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.