Bussines objects

  • Thread starter Thread starter Radi Radichev
  • Start date Start date
R

Radi Radichev

Hi!
I'm making a database application and i heard from a friend that it is more
proffecional and easy to do this with bussines objects. Can anyone tell me
where i can find more info on bussines objects and how to implement them
with c#? I would appreciate any help. Thanks.
 
A "business object" is just a class that represents a real entity with
which you work. For example, if you work with customers and orders, then
you might have a Customer class and an Order class.

Check out the following link:

http://www.mygenerationsoftware.com/dOOdads/dOOdads.aspx

The tool from MyGeneration can create C# code for business objects
automatically from tables in a database. Then you can bind controls in
your gui to that.
 
A "business object" is just a class that represents a real entity with
which you work. For example, if you work with customers and orders, then
you might have a Customer class and an Order class.

Check out the following link:

http://www.mygenerationsoftware.com/dOOdads/dOOdads.aspx

The tool from MyGeneration can create C# code for business objects
automatically from tables in a database. Then you can bind controls in
your gui to that.

As useful as you might think such a tool is, I would seriously advise
against using database design as the foundation for class design. There are
several patterns, like foreign keys, that are not necessarily correct in OO
world.

e.g.

Database
========
SalesOrder
ID
Date
CustomerID (FK)
Tax
Total

OrderLine
ID
OrderID (FK)
Quantity
ProductID (FK)
LineValue

Classes
=======
SalesOrder
ID (unique ID held internally, not used in client code, just by storage)
Date
Customer (object not ID)
Lines (composite list only accessed through AddItem method on this class)
Tax
Total

OrderLine
ID (unique ID held internally, not used in client code, just by storage)
Quantity
Product (object not ID)
LineValue

It is usually the job of a mapping layer to maintain the solution to this
apparent mismatch between the Object Layer and the Database.

Joanna
 
I wholeheartedly disagree wtih this statement.
As useful as you might think such a tool is, I would seriously advise
against using database design as the foundation for class design. There are
several patterns, like foreign keys, that are not necessarily correct in OO
world.

Your application in the end exists only to manipulate data, the data is the
application, everything line of code your write exits to flip a bit or save a
value in your database. Starting with the database and working from the
ground up is an excellent and proven way to write an application, and is how
most do it.

Once you have your database design you can then use that very useful AND
accurate data to generate the classes that represent that data. MyGeneration
does exactly that.

Mike Griffin
MyGeneration Software
http://www.mygenerationsoftware.com
 
MyGeneration said:
I wholeheartedly disagree wtih this statement.

You are entitled to your opinion but...
Your application in the end exists only to manipulate data, the data is the
application, everything line of code your write exits to flip a bit or save a
value in your database. Starting with the database and working from the
ground up is an excellent and proven way to write an application, and is how
most do it.

Database design used to be the standard, well-proven basis for non-OO
applpications; I know, I was weaned on Logical Data Structure diagrams.

But where do you put the code that manipulates the data ?

Please don't tell me you use data-aware controls directly connected to
database tables and write the code in event handletrs on the forms!! :-))

Not all data in an application is stored in a database. In a well designed
OO application you may well have hundreds of classes that have nothing to do
with *stored* data.

The frameworks I have written to support my applications contain around 300
classes and interfaces.

There is the Value Type Framework that gives me more metadata about my
business objects and their properties.

There is the Object Persistence Framework that allows me to write OO code
that knows nothing about databases because the OPF translates business
objects to/from database tables, generating SQL on the fly. I only ever use
one Query component, one Transaction component and on database component in
my entire application and frameworks combined.

There is the MVP framework that allows me to replace my UIs without having
to change any of the code in either my business objects or the applications
that use them.

etc...

How would I extract those classes and interfaces from a database ?

What about those applications that don't use databases ?
Once you have your database design you can then use that very useful AND
accurate data to generate the classes that represent that data. MyGeneration
does exactly that.

How does your software translate the Sales Order example I gave ?

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
 
Hi,


MyGeneration said:
I wholeheartedly disagree wtih this statement.


Your application in the end exists only to manipulate data,

No really, my application exist to solve a problem to the user. The data is
the core of it , but you cannot design all your application around it, you
have to design your application around the problem you are trying to solve.
Starting with the database and working from the
ground up is an excellent and proven way to write an application, and is
how
most do it.

Totally agreed with you, The DB design helps you identify the potentials
entities involved in the business layer and the relationships among them,
Now where I disagree with you is that you should take into account that the
requirements of the business layer is different that those of the DB layer,
ie you don;t have a third normal form for business layer that can assure you
have a good design.
The relationship among buss. entities are differents and others patterns
exists for this layer.
Once you have your database design you can then use that very useful AND
accurate data to generate the classes that represent that data.

About the original post question....

There are being lot of discussions in this groups about what is the best
approach to handle data in the business layer, You have two escenarios ,
when the business rules are simple and few and no transformations need to be
performed in the data itself, in another words the main use of your app is
showing/editing data. In this escenario IMO is better to keep the data in a
dataset.

IF you have complex business rules and relationships then you are better
creating custom business objects that better describe the problem.
MyGeneration does exactly that.

That may be a very useful tool !!!!
I started using a similar feature in Rational's XDE but I never could figure
out how.

Do you provide a demo version ?

Cheers,
 
There are samples on our home page. As for a demo version MyGeneration is
100% free, there is no trial version, it's simply free. We also have
Gentle.NET, NHibernate, Opf3, and DAAB templates in addition to our own
dOOdads architecture.

And I don't care what the business requirements are I aways generate the
code and customize from their (without worrying about regeneration), see this
page:

dOOdads at 10,000 feet
http://www.mygenerationsoftware.com/dOOdads/dOOdads.aspx

We use this technique on Fortune 50's and 100's and it works everytime, our
clients are simply amazed by our speed and reduced cost, and above all the
maintainability.

dOOdads usage in C#
http://www.mygenerationsoftware.com/dOOdads/CSharp_MasterSample.aspx

Everyone has their own opinions sure, but your saying "Don't do that it, it
only works on simple projects" without offering any proof.
 
Hi,

We use this technique on Fortune 50's and 100's and it works everytime,
our
clients are simply amazed by our speed and reduced cost, and above all the
maintainability.

The size of the company does not mean nothing, it's the requirements and
complexity of the system what does.
A complex system will get better beneficies of the framework of course.
dOOdads usage in C#
http://www.mygenerationsoftware.com/dOOdads/CSharp_MasterSample.aspx

Everyone has their own opinions sure, but your saying "Don't do that it,
it
only works on simple projects" without offering any proof.

I did not say that. I said that this is a recurring subjects in the
newsgroup. and that several strategies are followed by different developers.
I personally do not disregard a dataset or datatable to keep data all the
way up to the UI, and do use it when the data is only to get dumped. It has
worked for me before. When using it? well that's the decision (and taste) of
the designer :)


cheers,
 
Yeah People that's verry nice but what i asked for was some Info on business
objects, not software for automaticaly implementing them.
 
Yeah People that's verry nice but what i asked for was some Info on business
objects, not software for automaticaly implementing them.

Business Objects is a term used for any class that describes a business
concept; e.g. Customer, Invoice, Person, Shape, Computer, Vehicle, etc.

The big advantage of using BOs is that all your business logic resides in
those objects rahter than being placed in event handlers on forms.

Most folks who start using a RAD IDE like VB, Delphi or VS, tend to place
database components on a form, hook up data-aware components directly to the
tables in the database and then try to figure out which event to place code
to react to changes in either the tables or edits.

This approach is doomed to fail (or take longer to get right) for all but
the simplest of projects.

If you design your BO layer, it need know nothing about either database or
UIs. This means that all your business logic is encapsulated in the BO layer
and you can change your database or UI without having to re-write.alter any
of your business logic code.

That is essentially what business objects are; however, to use them
efficiently, you will also need some method of translating the values in the
properties of your BOs so that they can either be stored in/retrieved from a
database or displayed in edits on forms.

This is where frameworks like OPF or MVP come in useful (see my other post).
However for UIs created in .NET, as long as your BO classes are designed
correctly, it is possible to use 'data-aware' controls to hook up directly
to the properties of your objects and to your lists of objects.

Does this answer your question any better ?

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
 
Your application in the end exists only to manipulate data, the data
is the application.

Well, I wholeheartedly disagree with _that_ statement. :)

Data is how things (business entities) happen to be stored. It is
common practice to put what the business thinks of as multiple entities
into one table (or set of tables), just because they share many of the
same (data) qualities. It is also common practice to split what the
business thinks of as one entity across multiple tables (normalization,
for example).

Where I work, we are dealing with exactly this problem: designing
business objects to represent real "things" in the business, _not_
database tables! Our case is probably worst-case because we didn't
design the database tables and we aren't at liberty to change them very
much. If we used an automatic business-object-generating technology, it
would produce crap: garbage in, garbage out. We're designing the
business layer to _hide_ the baroque complexity of the data model as
much as we can. The last thing we want to do is expose it at the top
level.

Again, that's a worst case. In those cases in which you're designing
the data layer and the business layer, there is a strong correspondence
between the two, but it's by no means one-to-one.

That said, generating a second-rate business layer "automagically" from
a database schema may be, in the end, the most efficient path. It's the
old 80/20 rule: to get 80% of the effect you put out 20% of the effort.
If you want a "perfect" business layer then it's going to cost you big
time. If automatically generated business objects are only 80% as good
as hand-tooled ones, but come at a quarter the cost, maybe that's a
smarter way to go. :-)

In response to the OP, so far I have seen two different approaches to
building business objects in .NET.

The first is the one that Joanna outlined so well in her post of a half
hour ago: build a business layer by hand, where each object represents
an identifiable "thing" in your business. If you have a good database
design, your business objects will probably look a lot like your
database tables (but will by no means be one-for-one).

The second is the one that Microsoft seems to be pushing: have Visual
Studio generate strongly typed DataSets from the database tables, then
inherit from the resulting (automatically generated) classes and add
your business rules as additional methods or overrides of the methods /
properties that were generated by Visual Studio. I haven't tried this
myself, but it seems to be the approach that MS is pushing.

Whatever you do, whether you hand-tool your own business layer, or use
the Microsoft approach, or use some other tool to build your business
layer, the important thing is to keep business rules out of your Forms
/ Web forms code. User interface code has no business knowing that the
reason this control over here is disabled is that "orange widgets don't
have packaging" or some such thing. That sort of information belongs in
your business layer, and, as Joanna points out, filling your Forms
event handlers with business rules quickly becomes an enormous
spaghetti mess.
 
Joanna said:
As useful as you might think such a tool is, I would seriously advise
against using database design as the foundation for class design. There are
several patterns, like foreign keys, that are not necessarily correct in OO
world.

Please, theory first, practical blabla later.
A relational model is perfectly usable as a foundation for an OO model.
The reason for that is that a relational model represents entity
definitions (Chen, Codd) you can also define in your OO model.

If you use for example NIAM/ORM (Halpin, Nijssen) to model your
relational model, you'll have an abstract model, which is used to
produce your relational model, but also is a perfect base for your OO
version of that relational model. After all, the abstract relational
model IS the modelled version of the reality.
e.g.

Database
========
SalesOrder
ID
Date
CustomerID (FK)
Tax
Total

OrderLine
ID
OrderID (FK)
Quantity
ProductID (FK)
LineValue

Classes
=======
SalesOrder
ID (unique ID held internally, not used in client code, just by storage)
Date
Customer (object not ID)
Lines (composite list only accessed through AddItem method on this class)
Tax
Total

OrderLine
ID (unique ID held internally, not used in client code, just by storage)
Quantity
Product (object not ID)
LineValue

It is usually the job of a mapping layer to maintain the solution to this
apparent mismatch between the Object Layer and the Database.

It depends how you look at things. If you like the theory behind the
relational model (you know, 30 year old proven technology) and you also
like OO languages, you can perfectly merge them, if you start with the
relational model and use that model to use it in the OO world.

A 'SalesOrder' will not be a different entity in your world than in
mine. There is no mismatch, it's just semantics.

Your class model for example, produces slow(er) code: to add the
OrderLine to the database, I have to have a live SalesOrder object.
Though it should be enough to just have the SalesOrderID.

Deleting 1000 objects from the database, same thing.

Showing 100 sales orders with the customer name in a flat list? you
need to load the customer object as well. The relational model offers
you the power to do that differently: create a new attribute set (==
entity) on the fly.

Frans
--
 
Joanna said:
Database design used to be the standard, well-proven basis for non-OO
applpications; I know, I was weaned on Logical Data Structure diagrams.

But where do you put the code that manipulates the data ?
Please don't tell me you use data-aware controls directly connected to
database tables and write the code in event handletrs on the forms!! :-))

Why are some people just always grabbing an extreme end of the spectrum
to make their point. You know very well there are a lot of different
solutions to place behavior correctly.

In fact, there are 3 kinds of behavior on data:
- attribute oriented behavior (ID > 0)
- entity wide attribute oriented behavior (order date <= shipping date)
- cross entity entity oriented behavior (customer is gold customer if
ordered at least 10 orders with producs a, b or c in the last X months)

the first two are perfectly placable inside entities, the 3rd isn't, as
you run very soon into problems with fragmentation of functionality,
i.e.: you have a set of functionality defined and the implementation is
fragmented across various entities. This makes a system hard to maintain
Not all data in an application is stored in a database. In a well designed
OO application you may well have hundreds of classes that have nothing to do
with *stored* data.

No offence, but when I design a business application, I don't think in
classes or objects. I think in entities, their relation between them and
define them in NIAM/ORM models. The customer can perfectly understand
them, as they contain scentences, like "Customer Has Order", "OrderLine
belongs To Order". Throw in the good old stuff from mr. yourdon and you
can perfectly design your system, without having to go through the
awkwardness of using implementation details.

The fun thing is: the design of the application is abstracted: you can
check if it's correct without writing 1 line of code or even think of
which class has to inherit from which. The other fun thing is: if you
use these diagrams as the guides what you have to implement, you have a
1:1 projection of what you have designed onto an executable form of it:
the code and _vice versa_. This means that I can look into the code, and
go back to the abstract models because that connection is there. The
other way around is also possible.

This isn't science fiction, this is reality for system designers for
over 20 years. I know what the domain model is, and your reasoning comes
from it, but don't bring it as if before the domain model software
developers were just doing unstructured things without any theoretical
basis. On teh contrary.
The frameworks I have written to support my applications contain around 300
classes and interfaces.

that's nice, now let's look at what you have to do when I present you
an enterprise db with 1300 tables.
There is the Value Type Framework that gives me more metadata about my
business objects and their properties.

There is the Object Persistence Framework that allows me to write OO code
that knows nothing about databases because the OPF translates business
objects to/from database tables, generating SQL on the fly. I only ever use
one Query component, one Transaction component and on database component in
my entire application and frameworks combined.

So do I, though I do start from the relational model.
There is the MVP framework that allows me to replace my UIs without having
to change any of the code in either my business objects or the applications
that use them.

MVP framework, hmm. ;)

But what you describe here is just normal n-tier goodness: you write a
BL layer which acts on its own, so you can place on top of it a gui tier
which can work on its own, consuming the services of the bl tier...
that's also ancient tech, and not OO related
How would I extract those classes and interfaces from a database ?

You have a system design, abstracted. That design learns you about an
entity 'Customer'. That's an abstract thing, it's build up from
attributes, like 'CustomerID', 'CompanyName' etc.. You know, the basic
CS stuff.

That model leads to a relational model. You can use that relational
model to build your entities, as they represent the same thing: the
entity. Then you write your BL tier which represents your application
functionality and you place the 3 types of behavior related to entities
at the right places.

DONE. No-one generates a gui from a db schema, as the gui should be
designed for useability and should be the frontend for the functionality
realized by the application. So on a screen you can for example have
customer AND order information. That's perhaps nice for the screen, but
you aren't storing that info together.
What about those applications that don't use databases ?

well, what about them?
MyGeneration does exactly that.

How does your software translate the Sales Order example I gave ?

Well, how does your software represent objectified relationships which
represent m:n relations?

A detailed aspect doesnt make something 'wrong', as there isn't a
'wrong' or a 'right' side here. The relational model approach has 30
years of proven technology on their side, you represent a new vision on
the matter. What's right and wrong is therefore a bit tricky to define,
as both camps will say the other side is wrong.

It's all about technical solutions for the data-access problem,
something which only exists in teh technical problem space. It doesn't
exist in the abstract functional problem space. There are different
solutions to that technical problem, and the one which fits with your
way of work depends on how you want to work, as there is no right or
wrong here. I wrote an article about that some time ago, you can find it
here:
http://weblogs.asp.net/fbouma/archive/2004/10/09/240225.aspx

Frans
--
 
Frans,

I am not a theoretical who likes to describes the why's.

However, in this kind of discussions I miss forever what is in Dutch called
the "Goederenstroom en Geldstroom".

Can you give me the correct English names for those two.

Thanks in advance.

Cor
 
Ignacio said:
Totally agreed with you, The DB design helps you identify the potentials
entities involved in the business layer and the relationships among them,
Now where I disagree with you is that you should take into account that the
requirements of the business layer is different that those of the DB layer,
ie you don;t have a third normal form for business layer that can assure you
have a good design.
The relationship among buss. entities are differents and others patterns
exists for this layer.

It depends on how you look at things. Some will say that a 'SalesOrder'
is a business object, which aggregates the entities (!) Customer, Order,
OrderLine, Address, Employee.. so the software on the BL level can work
with a single object which embeds all the right information: the
SalesOrder. Other people will say: no, the concept of the SalesOrder as
a business object doesn't really exist. I just have entities: Customer,
Order, OrderLine, Address, Employee and these have relations, but the
behavior applied to them is only in a runtime context, e.g. the context
which process the SalesOrder, and that logic then thus works with all
these entities (in a graph or separately).

The BO approach can have advantages: you abstract away the contents of
the BO (which entities are aggregated inside it), though at the same
time, it is illogical to place the behavior of a SalesOrder outside the
salesorder. This can lead to fragmentation of behavior which spans more
than one BO. It also leads to problems if I want to use a subset of the
aggregated entities in teh BO in another context: I then have to create
another BO.

Frans

--
 
Frans,
Other people will say: no, the concept of the SalesOrder as a business
object doesn't really exist.

It is a legal document needed for every transaction.

In most however in our country for sure very much embedded by law (BW).

Without it not any process in a bussiness situation can exist in our
country.

The object in whatever way it is constructed represents that in the
information system.

Just my thought,

Cor
 
Michael,

I am not sure, what it says is that the (let take your words) flow of funds
is opposite to the flow of goods.

This is (in my opinion) the complete business approach you need for
information because those flows are around the objects that they use (and
get there information from or let them act because of that).

Cor
 
Please, theory first, practical blabla later.
A relational model is perfectly usable as a foundation for an OO model.
The reason for that is that a relational model represents entity
definitions (Chen, Codd) you can also define in your OO model.

A Relational model may well represent entities, but it can only represent
their state, not their behaviour. The best a RDB can do with behaviour is to
have Stored Procedures littered all over the database, with no encapsulation
between data and behaviour.

*The* fundamental difference between a relational model and an object model
is that the object model aims to encapsulate data, related behaviour and
responsibility in the one entity instead of having to link those things in
application code.
If you use for example NIAM/ORM (Halpin, Nijssen) to model your
relational model, you'll have an abstract model, which is used to
produce your relational model, but also is a perfect base for your OO
version of that relational model. After all, the abstract relational
model IS the modelled version of the reality.

I would have to strongly disagree with you; an abstract relational model is
just what is says it is: an abstraction of real life bound into a model that
is more concerned with relationships (PK/FK) than it is with an accurate
representation of the real world.

There is certainly an abstract model that reflects the real world that is
neither relational no object and it is possible to derive both relational an
object models from it. But you will find that the object model requires less
'massaging' to get it to work almost exactly as the real world.
It depends how you look at things. If you like the theory behind the
relational model (you know, 30 year old proven technology) and you also
like OO languages, you can perfectly merge them, if you start with the
relational model and use that model to use it in the OO world.

That's the problem; I don't like the theory behind the relational model. It
forces the model away from reality in order to comply with the rules of a
storage mechanism.
A 'SalesOrder' will not be a different entity in your world than in
mine. There is no mismatch, it's just semantics.

The mismatch is not in the Model, it is in the implementation of the Model.
Your class model for example, produces slow(er) code: to add the
OrderLine to the database, I have to have a live SalesOrder object.
Though it should be enough to just have the SalesOrderID.

I very much doubt that, which takes longer: inserting a Sales Order record
followed by a number of Order Lines within one transaction, or inserting a
Sales Order followed by a number of Order Lines within one transaction ??

The SQL generated by my OPF is identical to that required to store entities
to tables without OO.
Deleting 1000 objects from the database, same thing.

With an OPF, same SQL, same thing.
Showing 100 sales orders with the customer name in a flat list? you
need to load the customer object as well. The relational model offers
you the power to do that differently: create a new attribute set (==
entity) on the fly.

You really haven't worked with OPFs, have you ? :-))

A well designed OPF is a highly optimised piece of kit that only loads IDs
and enough properties (usually one) to allow users to browse lists. Thus to
load a Sales Order, your generated SQL would look something like :

SELECT ID, ORDER_REF, ORDER_DATE, CUSTOMER_ID FROM SALES_ORDER WHERE ....

Certainly an object is then created for each Sales Order but not all the
properties are loaded; the rest can either be loaded on demand or the full
object will be retrieved, based on the ID, when the object is first shown
for editing. The only time that full objects are ever loaded is when one of
them needs editing; the others in the list remain as partially loaded
objects.

Object properties (like Customer) contain a Customer object that only has
the ID and Name properties loaded.

I have been working with OR mapping for many years now and certainly started
with the view that classes could be derived from tables, but my years of
experience have matured my views to realise that there is a very real
impedance mismatch between relational and object models. See my example of
the Sales Order; a relational model will treat an Order Line as a separate
entity from the Sales Order that it is a part of; the object model enforces
the composite nature of the relationship by ensuring that the only way you
can add a new Line to an Order is by asking the Order to do it for you.
Since when did you ever see a real world Order Line that wasn't contained
*within* a real world Sales Order ?

The object model also allows concepts foreign to relational modelling like
inheritance, aggregation and composition. Concepts that are very much a part
of the real world but that take a lot of effort to match in the relational
model; I should know, I have to write the OPFs that cross the mismatch :-)

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
 
It depends on how you look at things. Some will say that a 'SalesOrder'
is a business object, which aggregates the entities (!) Customer, Order,
OrderLine, Address, Employee.. so the software on the BL level can work
with a single object which embeds all the right information: the
SalesOrder.

And they would be wrong. A Sales Order is a Composition that contains 1..n
Order Lines; it also holds references to but does not aggregate a Customer.
The Order Lines each describe a quantity of a Product to be allocated to the
Order and hold a reference to that Product.

Your description looks more like an unnormalised Excel spreadsheet :-)
Other people will say: no, the concept of the SalesOrder as
a business object doesn't really exist. I just have entities: Customer,
Order, OrderLine, Address, Employee and these have relations, but the
behavior applied to them is only in a runtime context, e.g. the context
which process the SalesOrder, and that logic then thus works with all
these entities (in a graph or separately).

And they also would be wrong. Does the fact that a Sales Order is put away
in a drawer mean that its Lines become separate entities, except when I want
to look at the Order ?
The BO approach can have advantages: you abstract away the contents of
the BO (which entities are aggregated inside it), though at the same
time, it is illogical to place the behavior of a SalesOrder outside the
salesorder. This can lead to fragmentation of behavior which spans more
than one BO. It also leads to problems if I want to use a subset of the
aggregated entities in teh BO in another context: I then have to create
another BO.

As I have already said the benefit of OO design is the correct allocation
and encapsulation of behaviour relevant to the data it affects. I suggest
you look at the concept of Responsibility Driven Design; Timothy Budd wrote
about this in his book Object-Oriented Programming.

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
 
Back
Top