Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

classes identification

 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi can anybody help me in finding classes and attributes of class in following statement: User wants a coffee from machine.

Thanks in advance.

Regards,
Nitin
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I hope this question isn't just a joke

You could for example model three classes: user, machine and coffee where coffee in turn is an attribute of machine because you can obtain a coffee (object) from a machine (object). Machine could have a getCoffee() method to encapsulate the coffee attribute. getCoffee() could be called by a user (object) to actually get a coffee.

Anyway modeling is always a matter of opinion. For non-trivial applications there could be many ways to get it perfectly right.

Marco
[ March 27, 2008: Message edited by: Marco Ehrentreich ]
 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks and it was definitly not a joke. as i am new to designing so just wanted have a grasp how to visiualize a problem statement into class diagram model. Anyways Thanks i will be needing your help in near future.
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem at all. Just let me know if you need help. But keep in mind that in design there's often no one and only best way to design an application and my hints are just possible suggestions, too, as I already said.

On the other hand I understand your problems. If you're new to this subject later you will often notice that you wanted to make something too perfect or you make it more complicated than the problem actually is. If you have another excercise of this kind just give it a try and I can hopefully tell you if it's totally wrong or if you are on the right path

Marco
 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sure macro. your words inspired me.

thanks
 
Eric Nielsen
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I would approach it slight differently. I see three objects in the use case:

User
Coffee
Machine

No attributes are actually exposed in the problem statement, but I would expect to have the following attributes on the objects:
User: name/some form of identifier
Coffee: size?, caf/decaf, blend
Machine: list of types of coffee offered, list of sizes, quantity of beans/blends/etc remaining

If its a coffee vending machine, then perhaps you also need to add costs to the coffee and notions of money/change on hand in the machine, etc
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric, of course you're right!

I didn't mean that only the classes or attributes given in the problem statement would be needed to implement the functionality of the classes and the whole design of a working application.
Perhaps I should have mentioned it explicitly but I thought it's obvious that there will be some more details you need to think about when you try to actually create a functioning program. And of course I hope Nitin didn't get me wrong in this point!

Marco
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not even sure why you want to model this problem statement with classes. What is the purpose of doing it?
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought it was just for doing some private exercises to get a feeling for object oriented modeling or design.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marco Ehrentreich:
I thought it was just for doing some private exercises to get a feeling for object oriented modeling or design.


If that's the case, I'd want to point out that what has been modeled here until now is the *problem* space. Which doesn't tell you much about the structure of the solution. With other words, the "classes" that you have modeled for understanding the problem are most likely not good classes you would want to implement in Java.
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course you are right, Ilja. There may be a big difference between using UML modeling for analysis in contrast to modeling the design of an application.

On the other hand as this example isn't too complex and to have a starting point I think it's better than nothing at all. The analysis model won't differ very much from the final design model with such a small example. But as you said it should be mentioned that a first analysis model doesn't necessarily have to be very similar to the final design model of the application you want to implement.

Unfortunately it won't be possible to explain or teach the art of perfect modeling and design in a few sentences here in this forum at all. I hope my first answers didn't give the impression that really good modeling and design is that easy and can be explained in only a few words.
 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Marco,

Your answer atleast gave me start point or i must say direction of thinking. I know final design come up after lot of iteration. I thought forum is the best for discussing the things. I found this forum helpful.

Regards,
Nitin
 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can yo people suggest me good book on uml modelling which has some case study with it.
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nitin,

I'm glad that you found the discussion at least a bit helpful

When I started to learn designing and modeling I found it very useful to read a lot about design patterns though this is just a part of the whole story. A good starting point might definitely be one of those books:

http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1206700483&sr=8-1
http://www.amazon.com/Head-First-Design-Patterns/dp/0596007124/ref=pd_bbs_sr_2?ie=UTF8&s=books&qid=1206700483&sr=8-2
http://www.amazon.com/Design-Patterns-Java-TM-Software/dp/0321333020/ref=pd_sim_b_img_29

For UML I unfortunately have only German books at hand but this probably won't be very helpful for you.

The following book which covers the whole process of OO analysis and design might be a very good start, too, but I personally haven't read it yet:

http://www.amazon.com/Object-Oriented-Analysis-Applications-Addison-Wesley-Technology/dp/020189551X/ref=pd_sim_b_img_23

Perhaps someone else can comment on it?!?

Marco
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"UML for Java Programmers" by Robert C. Martin actually has a chapter where he discusses the UML design for a coffee machine. He starts with a "naive" design, with classes like Boiler, WarmerPlate, Button etc., and explains the problems with that design. Then he shows how to come up with a good OO design that looks *very* differently, with classes like UserInterface, HotWaterSource and ContainmentVessel. The rest of the book is quite good, too.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic