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 ]
Joined: May 19, 2005
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.
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
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
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!
I'm not even sure why you want to model this problem statement with classes. What is the purpose of doing it?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I thought it was just for doing some private exercises to get a feeling for object oriented modeling or design.
Joined: Jul 11, 2001
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.
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.
Joined: May 19, 2005
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.
Joined: May 19, 2005
Can yo people suggest me good book on uml modelling which has some case study with it.
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:
"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.