• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

tip on design

 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank

is there any site where we could post application and people give feedback on code and design?
 
Marco Ehrentreich
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
brevity is the soul of wit - shakepeare. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic