|
For not making another topic, I have an encapsulation debate with myself:
Account contains List< Contact > and List< ContactGroup >, and methods to manage these..
How should I DECIDE if I should encapsulate all the contacts classes and methods in lets say an AddressBook class?
The same for other things contained in Account, like all concerning Messages: List< Labels >,List< Messages >, List< MessageThread > and methods..
My great question would be that if I have a lot of encapsulation, then I would have a lot of inbetween methods, from the main application to the object itself, like...
Application.AddLabelToMessage()
calling Account.AddLabelToMessage(msg, label)
calling MessageManagerOrSomething.AddLabelToMessage(msg, label)
calling certain Label as Label.AddMessage(msg)
Please have patience, i'm learning to model well (I know these can be done either way)
Again sorry bad eng.
|
|
|
|
|
How should I DECIDE if I should encapsulate all the contacts classes and methods in lets say an AddressBook class?
Does the word ('AddressBook' in this case) come up often (preceded by 'the') when you talk or think about the design and how to do it? If so it's probably a good contender to be an object. Then, consider if you can come up with messages (methods) such as Set...., Get....., Do....., that you would use on this object to have it do things.
Should one class contain other classes?
Ask: "Does Class1 have a Class2 OR Is Class1 a type of Class2, if its the first one, Class 1 should contain Class2.
Consider your: List<messages>, what happens if near the end of your coding you decide to change to, say vector<messages> or String Messages[50]. If you've written a class CMessages with methods, say, GetMessage(...) and AddMessage(..) which encapsulate this, then it's no problem. If youve used list here there and everywhere in the code it can be a real problem to change them all.
a lot of inbetween methods?
Being able to call Application.AddLabelToMessage(...) is probably better than needing to use four or five lines to get one object, then another from that, then another from that and finally to call, say, MsgHeader.AddLabel. You don't want to bother low level objects like, say, MsgHeader objects at a high level. Just calling AddLableToMessage hides the complication that (may) be in the method from the caller. Encapsulation is all about hiding complication.
In the end, does it feel right? This may take experience but if it feels right, go for it.
|
|
|
|
|
*i am a starter , trying to learn the GOF patterns.
i am using vb.net , understand c#. still wan't a job in holland as starter in vb.net .
i am a person who doesn't want to have full blown solutions , i want to learn by coding , what is happening deep inside the logic.
*i am trying to serialize my tree , filled with nodes that work like groups(with nodes) / transforms(leaf) / 3d-meshes(boxes/ball/other primitives) in a world node.
yes i am trying to share my servers '3d world' with my clients.
*but when i try to serialize my tree to xml , i end up with errors like :
-my leaf objects cannot have children.
-xml serializer cannot recognize what kind of object a child is.
*i am now trying to build my personal serializer , that breaks up my tree into a array of objects , and then seperately serializes each object.
*in the future i want to grasp the idea of sending the whole world state and the delta-state (difference in worlds , inbetween two times).
*did anybody found some examples. or know some ideas how to help me ?
Jarno Burger
Video Jockey
|
|
|
|
|
Hi,
trying to learn the GOF patterns
Good thing to learn about, I finally bought the book a few months ago.
trying to serialize my tree , filled with nodes
I had a look into serializing a tree and I got as far as serializing the objects contained within the nodes and leaves but not the actual 'tree' information such as child/parent/leaf used to construct the tree. Which meant I could not reconstruct it. When running my (C++) program I used a Windows tree control CTreeViewCtrl to visualize the data and a third party tree container to actually hold and manipulate the data and linked the two together.
I serialized the various classes that made up the objects held in the tree container using the Boost library but was not serializing the container structure. The question then arose as to should I serialize the container - which would then make the program dependant upon that container. If I did, how?
This is where I left it a few months ago.
my leaf objects cannot have children.
Leaves cannot have children, thats correct
-xml serializer cannot recognize what kind of object a child is.
I used the Boost library which got round this by allowing simple additions to class code to allow each object, when serialized, to store what type of object it was - and what it inherited from. Reconstructing then created the correct objects.
|
|
|
|
|
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[^]
|
|
|
|
|