This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes tip on design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "tip on design" Watch "tip on design" New topic
Author

tip on design

mark smith
Ranch Hand

Joined: Apr 05, 2005
Posts: 246
hi

i would like to create a little application to link shape with line... like we can see with kivio, visio, argouml...

i beginning to write a abstract class, this class have position, dimension, rectangle

i have a class to draw square and another to draw relation

do you think is a good design chooce if theses both class extend this abstract class?
do know if a good idea to think line is like a rectangle...

thanks
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi Mark,

do you think is a good design chooce if theses both class extend this abstract class?

Short answer: It depends The idea to have an abstract concept for all shapes doesn't sound too bad for the type of application you describe. On the other hand you should be aware that Java doesn't allow multiple inheritance and that inheritance is generally more difficult to handle and should only be used if there a strong relationship between your parent class and children classes. So if really all shapes are very, very similar an abstract base class may be a good choice. If you just need some functionality all shapes should have in common it may be easier to define an interface for this common concept. But as with all design decisions it's hard to give a single correct answer, in particular without knowing all the details about an application and its requirement.

do know if a good idea to think line is like a rectangle...

Same here: it depends. At first sight it doesn't make very much sense. In "reality" a line is NOT a rectangle so you should have a good reason to treat it as a rectangle in your app. Possibly you just want to define a thickness for a line? Then it may be only an implementation detail and you should model a line as line.

Marco
mark smith
Ranch Hand

Joined: Apr 05, 2005
Posts: 246
my idea is to create a db designer who use crow's foot notation

http://www.tdan.com/view-articles/7474
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

This sounds like an ambitious goal. I guess especially the graphical layouting of shapes and components is nothing trivial.

Regarding your questions above, I'd still try to get away without inheritance (abstract base class) which will make it easier to support all sorts of different shapes. Of course then you will still have to find a good design for a common interface for all shapes.

What I still don't see here is the need to model a line as a rectangle. Perhaps you should try not to mix domain concepts with graphical implementation details. A line is a line, maybe with additional things because of the crow's foot notation. But in my opinion this only has to do with the way you will have to draw different kind of lines. Or if you have to draw a thick line then maybe you will have to use a rectangle to make it appear as a thick line but in your problem domain it's still a line.

Marco
mark smith
Ranch Hand

Joined: Apr 05, 2005
Posts: 246
ok i think i will follow your advice

model class
i create a class entity, this classs have a list of attribute

i create a class relation, this class include 2 entity and cardinality

now graphic class

entityDrawable will have an entity

entityRelationDrawable will have 2 entity and one relation any comment, better way to do it, better oo design?
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi Mark,

the last description of your application plans is a lot more generally usable than the first one.

If you separate the domain model completely from the graphical representation you would be free to draw a diagram with any visual technology you like. The good thing is that the entity and relation classes wouldn't have to know anything about the user interface.

On the other hand I should mention that this may complicate the application design, too. You would have distinct application part to model the diagram with all the relationships etc. and another part to draw a diagram. Depending on the situation this may be worth the overhead.

There's basically nothing wrong with both approaches. This is probably not the answer you like to hear, but unfortunately when it comes to software design there's rarely anything just black or just white. A lot of things depend on your current or future requirements, the environment where your application should run, maybe the audience to use the application and a lot more.

What I mainly wanted to tell you with my advice above is, that I don't think it's a good idea to treat a line as a rectangle just because a rectangle is one way to draw thick lines. But besides that fact I don't think your first approach where every shape has the ability to draw itself is too bad

Marco
mark smith
Ranch Hand

Joined: Apr 05, 2005
Posts: 246
thank

is there any site where we could post application and people give feedback on code and design?
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi Mark,

I'm not aware of any web site where you get a detailed analysis of your code (at least not for free). In general you're right here on JavaRanch although my answers are probably not what you expected.

You should understand that there's definitely not a single correct solution to any non-trivial application. For this it would be difficult for anyone to judge the design of your application just by looking at the source code. It's at least equally important to know the detailed requirements for your application and to hear why you decided to do some things the way they are. What's a perfect solution for a problem in one context may be completely wrong or at least bad in another context even though the application solves the same problem. For example it may make a big difference to your application design whether your application should be very extensible (for example via plugins) or if you have special security requirements.

That said you should not expect to get a "wrong" or "right" answer to your design questions. Good software design takes much more time to learn than the plain syntax of a programming language. You simply need to practice as much as possible to gain experience. Even those who are very good in designing a software application won't always share the same opinion. So if one person tells you that the design of your application is excellent you will surely find another one who tells you that there is something which couldn't be worse. Of course this depends a lot on the size and complexity of an application. Opinions may differ more with big and complex application than with small and simple ones.

I hope this explains why I didn't tell you to make it this or that way or which way it's better. In my opinion you should make yourself comfortable with the basics of application design (there are some good books on this topic), make your own experiences and come here to discuss the details and share your thoughts with others

Marco
mark smith
Ranch Hand

Joined: Apr 05, 2005
Posts: 246
thanks a lot for all this good information

i would surely create a generic class to make life easier...

if i want to add a link or a link on a jpanel, i don't want to create two list to know all component i have on it....
same thing want i want to add or remove a entity or link
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: tip on design
 
Similar Threads
repaint problem, rectangle selected appears on second time
Hey Yall, does this look right?
Round Robin Class diagram
Factory Method and Builder
Simple drawing