tags:

views:

89

answers:

2

I have an extremely hard time figurering out how classes needs to communicate with eachother. In a current project I am doing, many classes have become so deeprooted that I have begun to make Singletons and static fields to get around(from what I get this is a bad idea).

Its hard to express my problem and its like other programmers dont have this problem. Here is a image of a part of the program: Class diagram

  • ex1. When I create a Destination object it needs information from Infopanel. How to do that without making a static getter in InfoPanel?

  • ex2. DestinationRouting is used in everybranch. Do I really have to make it in starter and then pass it down in all the branches?

Not sure if this makes sense to anybody :) Its a problem that is reacurring in every project.

A: 

There's just too little information here. For example, I am not even sure if MapPanel and InfoPanel should be the way they are. I'd be tempted to give the decorator pattern a try for what it's worth. I don't know why a Listener is a child of a Panel either. We need to know what these objects are and what system this is.

dirkgently
This is a application for MapRouting like googlemap.MainFrame: Frame so I can see my application.MapPanel: Panel that shows the map.InfoPanel: Panel so the user can input a destination via text fx.Listeners: Used so that something happens when I push on a button or wanna zoom in on the panel. Basicly giving the panels functionality.RouteClicking: Creates a new Destination according to where your mouse is and adds it to DestinationRouting so you can go from A->B->C->D...WorldRoute: Is the whole route. ie. A->B->C->D, while a normal route is just a destination A->B
bobjink
I think what I am doing is delegating every task out to new objects.Tell me if you need more info :)
bobjink
Looks a candidate for MVC from a high-level.
dirkgently
bobjink
+1  A: 

After looking at your class diagram, I think you are applying a procedural mind set to an OO problem. Your singletons appear to contain all of the behavior which operate on the records in your domain model and the records have very little behavior.

In order to get a better understanding of your object model, I'd try and categorize the relationships (lines) in your class diagram as one of "is-a", "has-a", etc. so that you can better see what you have.

Destination needs some information from InfoPanel, but not likely all information. Is it possible to pass only the needed information to Destination instead of InfoPanel?

What state is being captured in the DestinationRouting class that forces it to be a singleton? Does that information belong elsewhere?

Alex B
There is no has-a or is-a relationship. Its more like I delegate the job to new objects.Yes, I only need one field from InfoPanel to create the Destination objects. Getting that field when I create a Destination via. MapPanel is the problem.DestinationRouting just keeps track of every destination when you add or removes destinations. I made it singleton so I could easily access it.
bobjink