Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: UML Class Diagram

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default UML Class Diagram

    Hi there, I'm working on a currency converter which uses XML to dynamically retrieve exchange rates. Below is my class diagram so far:



    Uploaded with ImageShack.us

    The theory behind it is the selects the current currency + amount first. The currency name is then passed to the exchange rates class which retrieves the feed for this country and as it parses through stores the information in a hash map (currency, country as well as exchange rates in an array). The user then selects the desired currency and the desired currency name, current currency amount and hash table are passed to the converter class to carry out the conversion (the desired currency name is only needed as in the exchangerates hashtable inside there will be an array with the exchange rate of every country to that specific country so you just need the name to identify the correct rate). The converted amount is passed back and set as the desired currency amount and of course displayed to the user.

    My question is does what I have above accurately representing this in the best way? It also seems a bit too simple to me with the amount of classes I have...


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,358
    Thanks
    182
    Thanked 834 Times in 777 Posts
    Blog Entries
    5

    Default Re: UML Class Diagram

    Quote Originally Posted by LDM91 View Post
    My question is does what I have above accurately representing this in the best way? It also seems a bit too simple to me with the amount of classes I have...
    The best way is the way that works Seriously, what one programmer does another may do in a completely different way but each reach the same functionality...which one is better? Off the top of my head you could consider encapsulating ExchangeRates in the Converter so the UI doesn't even see ExchangeRates or how it is implemented. Might also consider making the Converter an interface. Both of these suggestions in my opinion would make the UI less dependent upon the implementation of these classes. However, ask me the same question in a week and I'll probably give you a different answer

  3. The Following User Says Thank You to copeg For This Useful Post:

    LDM91 (December 26th, 2010)

  4. #3
    Junior Member
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: UML Class Diagram

    Thank you for your reply. By encapsulating exchangerates in converter do you just mean effectively merging the two classes? My understanding is that it is best to have each class do one job only. I do take note of the first line of your comment, perhaps I shall put this design into practice and get it working then fine tune afterwards if I discover a better method to achieve the same result.

  5. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,358
    Thanks
    182
    Thanked 834 Times in 777 Posts
    Blog Entries
    5

    Default Re: UML Class Diagram

    Thank you for your reply. By encapsulating exchangerates in converter do you just mean effectively merging the two classes?
    They could be separate classes, but in the design I suggested above ExchangeRates would be a variable inside Converter. Relative to the diagram, the arrow coming from ExchangeRates would point to Converter.

    My understanding is that it is best to have each class do one job only.
    Good point but not always necessary and easy to do, and sometimes not easy to change later on...There are many ways to think about designs like this, from code efficiency to ease of making changes to code reuse. In larger projects a good design means taking all these into account. In general thinking about things such as what depends upon something else, how that depends upon that something else, if I change 'X' how will it effect the rest of the code, what is most likely to change in the code, if I move 'y' to a new class/interface, can I reuse it, etc...all things to keep in mind. Just my .02
    Last edited by copeg; December 26th, 2010 at 10:18 PM.

  6. #5
    Junior Member
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: UML Class Diagram

    Ah I understand what you mean the problem is exchangerates must know the currentcurrency value to retrieve the info as I don't want to achieve the currency info for all countries as they all have separate rss feeds to parse and this could be slow. I'm not sure how to access the currentcurrency using a different design as ui must use it too to set the currency in the first place

Similar Threads

  1. Replies: 2
    Last Post: April 21st, 2010, 11:25 AM
  2. need API for Connection Routing in Interactive Diagram Editor
    By pavan arepu in forum AWT / Java Swing
    Replies: 2
    Last Post: April 21st, 2010, 11:19 AM
  3. UML Diagram Help
    By chizzle in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 15th, 2010, 05:12 AM
  4. Replies: 0
    Last Post: April 11th, 2010, 09:56 AM
  5. problem with data access when a class call another class
    By ea09530 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 4th, 2010, 06:20 PM