File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes classes  identification 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 » Engineering » OO, Patterns, UML and Refactoring
Bookmark "classes  identification" Watch "classes  identification" New topic
Author

classes identification

nitin pokhriyal
Ranch Hand

Joined: May 19, 2005
Posts: 263
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

Joined: Mar 07, 2007
Posts: 1280

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

Joined: May 19, 2005
Posts: 263
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

Joined: Mar 07, 2007
Posts: 1280

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

Joined: May 19, 2005
Posts: 263
sure macro. your words inspired me.

thanks
Eric Nielsen
Ranch Hand

Joined: Dec 14, 2004
Posts: 194
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

Joined: Mar 07, 2007
Posts: 1280

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

Joined: Jul 11, 2001
Posts: 14112
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
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

I thought it was just for doing some private exercises to get a feeling for object oriented modeling or design.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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

Joined: Mar 07, 2007
Posts: 1280

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

Joined: May 19, 2005
Posts: 263
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

Joined: May 19, 2005
Posts: 263
Can yo people suggest me good book on uml modelling which has some case study with it.
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

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

Joined: Jul 11, 2001
Posts: 14112
"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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: classes identification
 
Similar Threads
Threads Alternative
A strange problem about the independent client
Inner class
Tomcat 4.0.1 - Servlet not found
Can We Define Our Own Data Structures In Java?