Skip to Content.
Sympa Menu

patterns-discussion - RE: [patterns-discussion] Design Help (Patterns?) for a Mapping

patterns-discussion AT lists.cs.illinois.edu

Subject: General talk about software patterns

List archive

RE: [patterns-discussion] Design Help (Patterns?) for a Mapping


Chronological Thread 
  • From: Jesús Alonso <kenchoweb AT hotmail.com>
  • To: j_simon AT sbox.tugraz.at, patterns-discussion AT cs.uiuc.edu
  • Cc:
  • Subject: RE: [patterns-discussion] Design Help (Patterns?) for a Mapping
  • Date: Fri, 19 Aug 2005 16:49:59 +0200
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/patterns-discussion>
  • List-id: General talk about software patterns <patterns-discussion.cs.uiuc.edu>

Hello Jörg.

Okay, let's see if I've understood correctly. The problem you're describing is that you need an already existing application to give a graphical representation of a set of objects defined by certain properties, stored in a dictionary, right?
So you have different types of objects, that instead of attributes (instance variables) are a set of Key-value pairs.

To allow the application to give a graphical representation of those objects, you've created a set of wrapping classes that would act as Adapters, am I right?

Well, this is a possible solution I see right now. You have a set of elements with both a model and a graphical representation. You have many different graphical representations, but the model has a common shape: A dictionary. This has a problem, that is subclassing and having large inheritance trees, as I understood from your explanation. For this, the Bridge pattern could help you a lot, separating the model and the view in two different classes. For what I've seen, the application relays heavily on the graphic part, so I would make the model (the dictionary) dependant of the view.

Also, for notification changes, the Observer pattern (and depending on the type of organization between elements, the Mediator pattern too) could help you solve that problem.

You can of course, create those elements with a lot of strategies (a set of Prototypes and a Factory Method, Abstract Factories...). Choose the one you like most. I'm sure none of them will give you many problems.

For the issue of the different parameters each object can have, as all them are view-dependant (you can't define a radious for a spline curve, for instance), you can delegate the responsibility of which parameters are in the dictionaries to the view part. Let me explain. Let be two classes: Model and View, and some subclasses of View: Spline, Circle, Square. Then, Circle would be responsible to introduce its radius into the dictionary, while none of the others (Square and Spline) could do. The responsibility of the properties integrity relay on each of them. The best way to do this would be to have the Key-value pairs in the dictionary with a String-String mapping. Of course, there are more elegant ways to do this, like for instance using a Property class and a collection of Properties instead of a String-String map, but that's your entire decission.

Tell me what you think about this, and specially if I did understand what you told correctly. I'm not sure about what you were talking about (sorry)

Hope that helps.


Hello Pattern Experts! :)

[short: content:
- description of the problem
- notes
- whats I have to use
- what I tried/thought about
- End (Question)]

I am a novice in Patterns and wnated to ask for statements, help, new idears for my following Problem:

Actually I am making a Practical course at a facility at the Technical University Graz, where I am developing a Client for a tool they use internally.

At that client there should be a mapping from some Objects and too their Properties to a graphical representation in form of a graph. So for Instance it could be something like this:

Type A ----> Node with Shape of a Circle

A with Property a1 -> The border is fat
A with Property a2, Value -> the Color varies between Green and Blue in 10 Steps according to the Value
A with Property a3 -> NodeColor = green

Type B ----> Node with Shape of a Triangle

B with Property b1 -> The border is fat
B with Property b2, value -> The color stroketype vaies according to the value

Type C -----> Link in form of a Polyline

C with Property c1 -> End of Line is a small circle
C with Property c2 -> End of line is a circle and an arrow

.....

Some things are to note: The Properties are all optional, I get Nodes and Links reported, however the Propertyies change for every Node/Link.

There might be that new Properties are added to the mapping after some time...

The mapping pf the Properies might change too (okay, it will ;), since it is a prototype and we first have to find the right mapping.... )

There should be a initial configuration which Property corespont to wich kind of mapping, the form of the configuration is not important at that point since it is a prototype, to this could be hardcodet in the programm, however it should be flexible.

Since this Prototype is a Windows Applikation we are coding in .NET {not my stuff normally ;) }, and for time-reasons the facility (the Know-Center at graz [www.know-center.at]) wants to bye the Nevron Diagram library (www.nevron.com), so the drawing of the diagramm works with that, and also the altering of shapes.

I have wrapperclasses for all the drawing done, since it fits easier in the model and we are shure we change the version of nevron as soon as the new one comes out, since this one desn't fit our needs.


What is defenite:

I have an Interface with which I get the elements reportet for drawing. There is a class which draws the nodes and makes the connection one by one. Since the mapping is always specific to just one element i also want to trigger the action at that drawing process.

I get the nodes reported in a very descriptive style, I get:
for Nodes:
the name of the node, used for labeling
an id, I use that to identify the node and make the connections
a dictionary with the properties. For those unfamiliar to .NET: a dictionary is a container with key/value pairs.
The Keys are the types of the Properties (like a1,a2,b1 in the example above) the values are optionally, but needed by some types.

What I thought about {and where i think it isn't good):

The maybe best idear at first:

IDEAR Nr. 1)

I am creating a function for every type of visual manipulation on the graph. I am having a hashtable where I store the Property as a key and a function pointer (a delegate in .NET i think) to the functions. There is an other function which is configuring that hashtable with the delegates.
Everytime I get a Object do draw I look in the Hashtable for the properties and call the registered functions.

Problems i see:
- There is no good way of extensibility according to the open-closed principle, which I want to follow here I think.
- I have to follow a specific set of parameters for every function if I don't want to have a big if then else if else part. If I get one the registration at a hashtable seems nonsence to me.
- I think too that it is hard to have different behavior for different reports which exist at the same time in the program (which might be true, but maybe not that important if we get a tooo complex solution for that problem {I am not shure if there is a simple one....})

IDEAR Nr.2

There are Objects for every type of visual manipulation of the graph. I am having some kind of store (like a hashtable) where I register the Objects to a property-key. So generally the same as above with objects:

Problems I see:
- The same with the decision code of fixed params as above
- There is the same problem with the different bahvior.

IDEAR Nr.3

Okay, now the things with too much patterns:

I thought of a chain of responibility, where I give the dictionary with the properties to appy inside as an argument, and every property who wants to have something to do with it makes it stuff. The Property class itself ist having an visual-mapping-object which is created over an abstract factory. There too exists a serier of visual mapping objects which implement the according behavior. The configuration is done by registering the right factories to the Properties Objects.

Problem I see:
- I tried do draw an UML diagram for that, and even here I got the feeling that is too complikated.

IDEAR Nr.4

Hm, I thought of making the visual mapping objects in means of a decorator pattern, who can be chained dogether. Everytime we have to draw an node/link the request is going to some desicion code (maybe too a chain of responibility), who just chains the decorators together so we get a configured element, on whom then a mapp() method is called

Problem I see:
- Okay, this was really much tooo much complcated and for our app defenitely an overkill.....

End (Question:)

Okay, none of the above solutions seemed satifacting to me, so I just wanted to ask for satements of my solution idears, and maybe idears what else I can do.
{okay, generally I am awaiting some magic pattern which is very easy to understand, very efficient, very fast, very small, easy to implement and so on ;) }

Thanks for any replies,
Jörg Simon

_______________________________________________
patterns-discussion mailing list
patterns-discussion AT cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/patterns-discussion






Archive powered by MHonArc 2.6.16.

Top of Page