Hi,
I have to write an application which extensively uses an SQL Database.
For a simple example say I have the following tables with the
appropriate fields.
1. Company (ID, Name, AddresseInfoID)
2. AddresseInfo (ID, Street, City, Zip)
(Those two obviously have a relationship)
Now I'd go and create an object called Company and one for the
AddresseInfo. AddresseInfo would be a public member of Company.
Usually you'll have more than one company to manage so I create a
strongly typed collection called CompanyCollecti on.
Now on to the questions:
1. Should each individual object be responsible of loading and saving
it's data from and to the database or should the CompanyCollecti on take
care of it (which IMHO seems a lot less coding to me on first sight)?
2. Assumed the Collection takes care of the data-fetching, how should
then the data changes whithin the individual objects be handled? What
comes in mind is either a IsDirty property of each of the
BusinessObjects (Company and AddresseInfo) (which can be checked by the
collection) or an event (say DataChanged) to which the collection would
hook up.
The problem I see with this approach is the following. Say my MDI GUI
displays a list of all Companies in a TreeView on the lefthandside. On
DoubleClick the selected BusinessObject gets displayed in a new
"Document Window" which hosts a PropertyGrid control. Now my user opens
3 Companies and changes the data of all of them. How would I then handle
the situation when he only wants to save to of those documents?
Here is some additional information which I feel might be usefull:
a. The amount of BusinessObject loaded from the Database is never really
huge. Say a maximum of 2000 objects.
b. BusinessObjects might contain collections of other BusinessObjects ,
e.g. the Company object will contain a EmployeeCollect ion.
c. The amount of different BusinessObjects will probably not exceed 20.
d. Performance issues are not a knock out criteria.
e. The solution that I'm after is simple to code and maintain. I don't
actually want to create a huge Framework with hundrets of classes which
provide for unlimited scalability and the forth. We are talking about an
application which is used by 10 people and new versions can be installed
at any time if required.
I hope someone can give me some advice on how to design this properly.
Thanks in advance,
Matthias 2 2895
Hi,
"Matthias S." <po*****@emvoid SPAMTRAP.de> wrote in message
news:un******** ******@TK2MSFTN GP10.phx.gbl... Hi,
I have to write an application which extensively uses an SQL Database. For a simple example say I have the following tables with the appropriate fields.
1. Company (ID, Name, AddresseInfoID) 2. AddresseInfo (ID, Street, City, Zip)
(Those two obviously have a relationship)
Does a company has more than one address? if not you better make the above
one table
Now I'd go and create an object called Company and one for the AddresseInfo. AddresseInfo would be a public member of Company.
I think that it depend of how you implement the other classes in your
design, if you need to treat the addesses in a particular way then yes, you
better do that, if not just make the AddresseInfo's members members of
Company
Usually you'll have more than one company to manage so I create a strongly typed collection called CompanyCollecti on.
Yep
Now on to the questions: 1. Should each individual object be responsible of loading and saving it's data from and to the database or should the CompanyCollecti on take care of it (which IMHO seems a lot less coding to me on first sight)?
It depends , I think I have use both approach,
You may have a static property named something like "Companies " that
returns a list of company. then you have a LoadList method and here is where
you decide who load the actual company.
You could decide to do a select * from company and have the LoadList fill
all the fields of the instances.
or you can do a new Company( companyID ) and let that each instance load
itself.
The later can give you more flexibility to what/when to load it, you could
create a "lazy" loading method, where an instance load itself when needed.
2. Assumed the Collection takes care of the data-fetching, how should then the data changes whithin the individual objects be handled? What comes in mind is either a IsDirty property of each of the BusinessObjects (Company and AddresseInfo) (which can be checked by the collection) or an event (say DataChanged) to which the collection would hook up.
That also depend of your app. You can implement such a method as you
describe, this will allow you to have a worker thread that iterate in the
collection and save as needed , NOTE that this will have BIG impact in the
concurrency protection that you use !!!!!!
Other method is having a Save() method in the Company class and that each
instance be responsible to save itself.
The problem I see with this approach is the following. Say my MDI GUI displays a list of all Companies in a TreeView on the lefthandside. On DoubleClick the selected BusinessObject gets displayed in a new "Document Window" which hosts a PropertyGrid control. Now my user opens 3 Companies and changes the data of all of them. How would I then handle the situation when he only wants to save to of those documents?
Use the second approach I described, a Company.Save() is issue as a
response to the user's save request.
Also take a look at a thread from last week named "Classes concepts"
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Matthais S.,
First, I would recommend using typed data sets for this sort of thing.
I would pass them through all layers of the application (front end,
business, data, etc, etc). They provide the heiarchical structure that you
want, easy binding capability, and all of the data classes will work with
them.
For the rest, see inline: Now on to the questions: 1. Should each individual object be responsible of loading and saving it's data from and to the database or should the CompanyCollecti on take care of it (which IMHO seems a lot less coding to me on first sight)?
If you use the strongly typed data sets, then this shouldn't be an
issue. Generally though, I would say that this is based on the type of
relationship that you have between the objects. If the object is a owned by
the parent, then I would say that you should load it at the same time. If
it is just a relation, then I would say you could load it when needed. As
for saving, I would say having two routines is fine, as long as they are
both called within the same transaction scope (after all, a change in one
should imply a change in the other from a logical perspective, since the
relationship is one where the parent owns the child). 2. Assumed the Collection takes care of the data-fetching, how should then the data changes whithin the individual objects be handled? What comes in mind is either a IsDirty property of each of the BusinessObjects (Company and AddresseInfo) (which can be checked by the collection) or an event (say DataChanged) to which the collection would hook up.
If you use typed data sets, you can use a DataView on them which will
allow you to see only the rows that are changed. The problem I see with this approach is the following. Say my MDI GUI displays a list of all Companies in a TreeView on the lefthandside. On DoubleClick the selected BusinessObject gets displayed in a new "Document Window" which hosts a PropertyGrid control. Now my user opens 3 Companies and changes the data of all of them. How would I then handle the situation when he only wants to save to of those documents?
If each has it's own window, then they should require some sort of user
interaction to commit the changes. Until the user does that, you won't know
if they want to be saved or not. It doesn't really matter, until the user
saves the items.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m Here is some additional information which I feel might be usefull:
a. The amount of BusinessObject loaded from the Database is never really huge. Say a maximum of 2000 objects.
b. BusinessObjects might contain collections of other BusinessObjects , e.g. the Company object will contain a EmployeeCollect ion.
c. The amount of different BusinessObjects will probably not exceed 20.
d. Performance issues are not a knock out criteria.
e. The solution that I'm after is simple to code and maintain. I don't actually want to create a huge Framework with hundrets of classes which provide for unlimited scalability and the forth. We are talking about an application which is used by 10 people and new versions can be installed at any time if required.
I hope someone can give me some advice on how to design this properly.
Thanks in advance,
Matthias This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Danimal |
last post by:
I have been using PHP for a long time... since it was called PHP/FI. I
have a programming design question:
Let say I have this class:
class attrib {
var $lenght;
var $type;
...
}
|
by: Nunaya |
last post by:
We have developed two objects called "customer" and "salesrep". For
simplicity, assume that these two objects will talk directly to a
database. The database has three tables: customers, customersalesreps
(allows multiple salesreps to be associated with a customer), and
salesreps. The customer object has business rules that allow
manipulation of customer information (add,update,delete,select,etc).
The salesrep object has business rules...
|
by: Jack Addington |
last post by:
I've got a fairly simple application implementation that over time is going
to get a lot bigger. I'm really trying to implement it in a way that will
facilitate the growth. I am first writing a WinForms interface and then
need to port that to a web app. I am kinda stuck on a design issue and need
some suggestions / direction.
Basically I have a business layer that I want to use to process any
dataentry logic (row focus changes, data...
|
by: shan chennai |
last post by:
hi...
i have a design as follows...
Presentation Layer (.aspx, .cs) -- Service Layer (just a facade) --
Business Layer (business objects) -- Data Layer (all DB related things
for business objects are done here) -- Data Access Application Blocks
-- DataBase
No we pass objects and not datasets across layers ..
|
by: CSharpguy |
last post by:
I have a 03 .NET web that does not use Typed DataSets, it uses a Busines
Layer/DataLayer classes. Alot of my reading on .NET 05 is using the DataSets
for the datalayer/business layer. I have a 05 web app that I used the
business/datalayer class architecture and it works. But my question is, what
is the recommended way in 05? DataSets or the 'Classes'?
Is there a best way or is it pretty much up to the developer on how to code
the...
| |
by: Sjaakie |
last post by:
Hi,
I'm, what it turns out to be, fooling around with 3-tier design.
At several websites people get really enthusiastic about using custom
dataobjects instead of datasets/-tables.
While trying to write such layers myself I got stuck on how to get
filtered or sorted data from the data-layer.
This is what I got:
Objects
|
by: Rob Meade |
last post by:
Hi all,
My web app is using a layered design, whereby I have UI/BOL/DAL layers....
So far things have been running fine and as the first app using this
approach I've seen some real benefits...
The problem I ran into yesterday had me in circles, and driving me crazy...
I have a following objects, class variables, properties and methods have
|
by: John Kraft |
last post by:
Friends,
I'm working on some crud stuff, and I was looking for opinions on the
subject. Below, I have pasted some VERY simple sample code. Class2
is a "traditional" crud type object. In a real example, these objects
would probably implement some kind of ICrud interface with the common
methods.
I'm finding that many times, though, I want to use these objects as
simple data objects, and I don't need all the database functionallity.
|
by: DS |
last post by:
I'm trying to understand how these two concepts could work together
architecturally (if they can.) I realize both concepts provide benefits
of re-use and ease of maintenance. Which is important when you are
setting up multiple sites that are similar.
But it seems like using both Design Patterns and Layered Architecture
together would create conflicts -- especially in the area of keeping
layers loosely coupled (and even physically on...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |