|
I would like to get some ideas on the best way to handle dealing with data in an object oriented system. Consider:
User
=======
UserId
UserTypeId
FirstName
LastName
OrganizationId
UserType
===========
UserTypeId
Name
Organization
============
OrganizationId
Name
District
YearFounded
How would you model these database tables with your objects?
For simple lookup table data, would User have a property for just UserTypeId or would it have a property of UserType(which includes both Id and Name)?
For more complex data, would User have a property for just OrganizationId or would it have a property of Organization?
If you go the route of having only an Id as property, how do you manage the display of property data, for instance, when displaying the User in the UI, you still need to display the UserType.Name value, and not just the Id. Would you load and cache a collection of UserType objects and use this to lookup the UserType.Name value when needed?
Would it make sense to expose a readonly property User.UserTypeName for convenience that provides the name value? I say readonly since you can edit the Id value, but not the actual UserType name when saving a user.
The object graph can grow large with several interactions... what rules do you use to draw the line as to where an object instance and its related graph stop?
Thanks for any opinions. Assume the objects must be WCF friendly for use as data contracts.
|
|
|
|
|
Firstly, I see no mention in your post of considering the "responsibility" of an object as part of the design process. This indicates your view of Object Oriented Design is far different than mine.
If you are asking how to mimic database table structure in your coded structures then that is an entirely different question. The most common method of doing that today is to use one of the many Object Relational Mapping tools to generate the code for you. Of course there are almost always problems associated with them but hey, if all you had to do was click a button then any monkey could do it and we would all be out of work.
Many people here on CP seem quite fond of using the new LINQ features in the .NET platform. Don't know if you can use that but if so I recommend looking into it.
|
|
|
|
|
Yeah, I guess my question is targeting the classes that might normally be created by an ORM. In our case, they are WCF data contracts, and have no behaviour.
The system also has other classes with behaviour, such as a UserBusinessManager class, that exposes methods for working with a User object, to perform actions like Load, Update, Insert, etc.
|
|
|
|
|
Hi,
the situation is as follows:
There are 2 classes - C1 and C2 - both inherited from an abstract class A. The reason is that instances of C1 and C2 are to be stored in an inhomogeneous collection, and a common base class (A) is used to access their functionality (textbook polymorphism).
The abstract class A defines an abstract method M. This is meaningfully overriden in C1, but has no meaningful override in C2.
Common sense would suggest to remove it from the abstract class if either of its derived classes are unable to override it meaningfully.
However, the logic of the situation requires M to be defined in the abstract class A.
My questions are these:
1. Is it a sign of good or bad design to write empty abstract method overrides?
2. Is it a sign of good or bad design to write abstract method overrides that only throw an exception informing the user of an incorrect usage?
3. How common are the empty abstract method overrides in real-world programming practice?
Your answers are greatly appreciated!
Lukas
|
|
|
|
|
Hi,
my 2 eurocents:
0. there is not only good or bad design, there is a continuum from very good to very bad
1. IMO overriding a method by an empty one because the functionality does not make sense is wrong.
2. throwing an exception in an override is OK
3. empty abstract overrides are only correct if that particular class needs a no-operation there; however I have never seen one.
4. FWIW, I would try and remove from the base class all functionality that is not meaningful for some of its decendents. If cats and dogs are mammals that eat and walk, and cats purr but dogs don't, then purr would not be a mammals method.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
It seems like you have a list of things, and you want to go through the list and perform an action which is only relevant to some things in it. In this case you could consider exposing an interface, and then when you iterate thru the list you can use if(item is INeedToBeNotifiedAboutEclipses) ((INeed..)item).YoItsALittleDarkOutHere();
|
|
|
|
|
Mark Churchill wrote: INeedToBeNotifiedAboutEclipses
No problem.[^]
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
|
We started getting requests to provide estimates for our development tasks, and I'm just wondering if there is a distinct breakdown into the technical design, implementation, and testing stages (from a developer's perspective) at other people's shops. If there is, I'd be curious to know what the ratios are (e.g. how much of the total development effort is spent on the technical design part, assuming you already have the preliminary specs?).
|
|
|
|
|
Of course, you should divide your development task into several stages: preliminary/concept design (~15%), detailed design (~15%), implementation (55%) and unit test (~15%).
|
|
|
|
|
If you have the requirements documented and putting aside the management and other support activities.
Technically the ration between System Design, Development and Testing is 25::50::25.
The Development will include Unit Testing.
This is a standard practice we follow for high level estimations... however the type of applications can make the ratio different.
|
|
|
|
|
Hi,
I have started to learn UML, are there any good websites with samples? I started with use cases.
Regards
|
|
|
|
|
|
|
Hi,
What are good software for UML diagrams? I would prefer cheap or free, but you guys can list any sort, commercial or free.
I tried Argo UML a while back, but not sure if it is efficiant for .NET 3.5?
Please let me hear your views.
Brendan
|
|
|
|
|
Try StarUML[^] - it's free.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys
|
|
|
|
|
|
Thanks guys. Is it good software? Or average?
|
|
|
|
|
StarUML is excellent. We use it to produce all of our design material through it's Word integration.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys
|
|
|
|
|
Pretty reasonable products they are, but as in all software, you have likes and dislikes, some you feel comfortable with, others not so and feel awkward. But try them out and come to your own conclusion.
ArgoUML is written using Java as is Visual Paradigm as is Oracle JDeveloper which includes some degree of UML. Star was written ( I think) with Delphi but as I recall, no longer being developed.
Sparx software via the link in my reply to your latest posting (above) is another paid-for product.
modified 1-Aug-19 21:02pm.
|
|
|
|
|
If I need to sketch something quickly, I use Dia. It's lightweight, has most of the features I normally need, and it doesn't really matter if you're a Windows or a Linux user--you can get a build that fits either: http://live.gnome.org/Dia/Download[^]
|
|
|
|
|
I have a method that could fail for a number of reasons, e.g. an invalid directory, a file not found in that directory, or an entry not found in that file. It's crossed my mind to throw different exceptions for the first two, and return null for the last, but this is not a good practice application of exceptions. My next alternative is to return null for any failure, but this makes unit testing the individual failures difficult. My third option is to return null for any failure, and set an ErrorMessage property on the class. If the method returns null, the caller can read this property and test/report on the error.
|
|
|
|
|
Hi Brady,
IMO you should come up with satisfactory functional specs first, independent of future implementation and/or testing concerns. Once the specs are cast, you can worry about implementing and testing.
You shouldn't burden the user with a more difficult API just because that makes testing easier, should you?
So, will the class user want exceptions? will he be happy with a null return and the need to check something else to find what went wrong?
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Luc Pattyn wrote: So, will the class user want exceptions? will he be happy with a null return and the need to check something else to find what went wrong?
The class use is me. I'd prefer the latter, but was wondering if anyone had any caveats with that approach.
|
|
|
|
|
Brady Kelly wrote: The class use is me
I thought as much, but it is rather irrelevant.
Brady Kelly wrote: but was wondering if anyone had any caveats
none here. It is somewhat similar to the Parse/TryParse situation.
They first offered Parse only, which throws whenever it feels like doing so.
Then came TryParse which doesn't tell you anything, except it returns a success flag.
I sometimes return a string, null=OK, non-null=error message (one step better than the old error number, 0=OK, negative=error; unless you need to check for a specific error that is).
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|