473,414 Members | 1,631 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,414 software developers and data experts.

Design Question für entity-base-classes

I have a baseclass named Entity. All stuff like Customer,Invoice,Article
and so on will derive from this class.
I have fields in the base class like "tablename" and "primarykeyname"
which is used to create the database operations on the class.

now the question is: how do I enable my base class to initialize these
values, but the values must not be changeable at a later time.

I do not want the variables to be set as in the baseclass' ctor:

public Derived():base("customer", "custID") // I don't want it this way

because I want to be able to add more variables at a later time without
breaking derives classes.

additionally I do not want these variables to reside directly in my
entitybaseclass but instead in a separate nested class which should be
accessible from outside the class with a property:

class BaseEntity
{
EntityParams parms = new EntityParams();

public EntityParams EntityParameter
{
get { return parms; }
}
}

But now the question is, how do I ensure that this object is NOT
modified after initialisation of the BaseEntity instance?
sure I could put Exceptions in each property.

And I do not want initialize the EntityParams class like this:

EntityParams parms = new EntityParams(param1, param2, param3...);

but instead I want to set the properties separately (so that later
additions of parameters do not break derived classes).

The funny thing is that I had a few week an idea of inventing
named/optional parameters which would solve exactly that problem :)

Is there a good solution for that? Did you ever stumbled across such a
problem?
Jun 20 '06 #1
1 1078
"cody" <de********@gmx.de> a écrit dans le message de news:
ew**************@TK2MSFTNGP03.phx.gbl...

|I have a baseclass named Entity. All stuff like Customer,Invoice,Article
| and so on will derive from this class.
| I have fields in the base class like "tablename" and "primarykeyname"
| which is used to create the database operations on the class.

Ugh!! this really is not a good idea, putting database code in a business
class, it is much better to try and separate out database stuff into a
separate "persistence" layer that knows how to translate objects into SQL
and vice-versa.

However, if you really want to do this, then create an abstract
CreateVariables() method in your base class and then override this in each
of your derived classes. Then you can call the abstract method in the base
class whenever you need to.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jun 21 '06 #2

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

Similar topics

20
by: Andy | last post by:
Hi All! General statement: FK should not be nullabe to avoid orphans in DB. Real life: Business rule says that not every record will have a parent. It is implemented as a child record has FK...
5
by: Guinness Mann | last post by:
If, after analysis, I determine that two tables have the same primary key, does that necessarily indicate that I really have two parts of the same table and they should be collapsed into one? ...
36
by: toedipper | last post by:
Hello, I am designing a table of vehicle types, nothing special, just a list of unique vehicle types such as truck, lorry, bike, motor bike, plane, tractor etc etc For the table design I am...
2
by: adamwoja | last post by:
Hi, Can anyone put a name to the following type of design... I need to be able to modify the amount/names of data "fields" stored for an entity so instead of representing the data stored...
3
by: cassandra.flowers | last post by:
I'm designing a database because I have to do it for the preperation work for my A-Level ICT exam. The database is for a building company. It has to store information on building projects...
11
by: Michael Thomas | last post by:
Hi everyone Not sure if this is the right newsgroup to be posting to for this question, but I am using Access 2002 to develop a database solution for the company that I work for. It's basically...
11
by: Arsen Vladimirskiy | last post by:
Hello, If I have a few simple classes to represent Entities such as Customers and Orders. What is the proper way to pass information to the Data Access Layer? 1) Pass the actual ENTITY to...
24
by: Kalpesh | last post by:
Hello All, Please help validate this design problem Assume that I have several entities in my project (eg Supplier, Customer etc). All of them save several common properties - name, address,...
11
by: Peter M. | last post by:
Hi all, I'm currently designing an n-tier application and have some doubts about my design. I have created a Data Access layer which connects to the database (SQL Server) and performs Select,...
23
by: JohnH | last post by:
I'm just recently come to work for an auto brokerage firm. My position involves performing mysterious rites, rituals and magick in order to get information out of their access database. This is...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
agi2029
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,...
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.