0

Note: I couldn't get formatting to work inside a code block for italics and things, so there is some makeshift markup to attempt to convey the meaning. Also the html escape character for a filled diamond would not work. Hopefully it still makes sense

I have a project in my Java class where I need to create a GUI program that basically models a small inventory database. The main focus is to create it in an object oriented manner. So basically before getting started I've mapped out a simplified UML which just specifies the classes, composition and inheritance without defining variables or methods - implementing those will be easy but I want to make sure I have a solid heirarchial structure of good object oriented design before I start adding in the details.

So if you could please take the time to look over my project structure and let me know if there's anything I should change, omit or add.

The project will basically be a makeshift video game store application that simply reads and writes records to a text file, and the administrator managing the database should have a graphical interface to navigate, add, delete, and edit records. I will spruce it up nicely with some great functionality, but for right now, I'm only focused on making sure my structure is good.

**list of classes**

DatabaseRecord <abstract>
VideoGameDatabaseRecord
DatabaseNavigator
Database <abstract>
VideoGameDatabase
Game <abstract>
VideoGame <abstract> (superclass for platform-specific video games)
XBoxGame
PlaystationGame
NintendoGame
etc for all subclasses that would pertain to the needs of the inventory

I'm still a little new to UML modelling, so I hope I've used conventions properly, and where text-based UML caused conventions to be impossible to follow, I hope the meaning is still clear with "a" and "c" inside diamonds to indicate aggregation or composition, and a capital "A" to indicate an abstract class (italics wouldn't show inside code markdown)

------A-----           0..*   ----------A--------                           ----A---             
| Database | <c>------------- |  DatabaseRecord |                           | Game |
------------                  -------------------                           -------- 
      ^                              ^                                          ^
      |                              |                                          |
      |                              |                                          |
---------------------      0..*  -----------------------------          1  ------A------
| VideoGameDatabase | <c>------- |  VideoGameDataBaseRecord  | <a>-------- | VideoGame |
---------------------            -----------------------------             -------------
         <a>                                                                ^   ^   ^  
          |                                                                 |   |   |  
        1 |                                                                 |   |   |  
-----------------------                                        -------------|   |   |  
|  DatabaseNavigator  |                                        |  XBoxGame  |   |   |
-----------------------                                        --------------   |   |
                                                                   -------------|   |
                                                                   |  PS2Game   |   |
                                                                   --------------   |
                                                                                    |  
                                                                            --------|
                                                                            | etc.  |
                                                                            ---------

Again, I'm looking only for guidance on the hierarchy, OOP design, composition etc. of my program structure. i.e. should this be abstract, should that be an interface, should I add more/less levels of subclassing, etc. I'm confident about churning out the code reliably, but my grasp and command of OOP design principles is still not good enough.

Thanks in advance for your help!

  • Do you really need the abstract type Game?' In your diagram it doesn't have relations to other entities. (BTW, maybe it would be clearer if you attach an image of the class diagram, there are free & good modellers over there such as Astah). – polypiel Feb 25 '14 at 10:31
  • I agree, but I think I might leave it there just for future extensibility - perhaps the imaginary store this inventory program is for would like to extend _their_ inventory to include board games, which would inherit things all games would have such as `String title;` and `float/double price;`, their accessors and mutators, `toString()`, and maybe a few more. But I do totally see how - regarding this project - class Game is basically pointless other than for semantic value –  Feb 25 '14 at 12:53
  • 1
    For extensibility, you may have the interface Sellable representing any item that can be sold. With methods for getting title, price... But unless you have a relation with VideoGameDataBaseRecord wouldn't make much benefit – polypiel Feb 25 '14 at 17:49

2 Answers2

0
  • "I will spruce it up nicely with some great functionality, but for right now, I'm only focused on making sure my structure is good. " That means, you should be sure it can take easily your great functions. :-)
  • Aggregation can be of three kinds - none, shared or composite. Saying aggregation instead of shared or shared aggregation is a bad error. Alas, widely spread from VP-UML tool.
  • For Abstract normally italic is used for name writing.
  • This one is much more serious problem: you have no different lines for associations and generalizations. It is therefore almost impossible to understand your diagram. But if I take that all arrows are generalizations, ... it makes sense! But really, better use some free tool for drawing. Community version of VP-UMP, for example. Or free Papyrus on Eclipse.
  • both your shared aggregations(allow me name them correctly, please) are strange:
    • The left one is simply not understandable - to write diamond on one end and 1-multiplicity on the other IS allowed (shared aggregations are not defined strictly in UML standard), but such unusual use should be explained. If your DB navigator works with many databases, the diamond should be on its end normally.
    • The right one is written in usual way, but I can't understand the sense under it - how it can be that one VideoGameDataBaseRecord has many games? I am not catching the logic. Could you repair it or explain it? I think, there should rather be normal association, with none aggregation, one- or two-sided, with 0..1 at the ends.
  • I am terribly sorry, but I do not understand what is in etc. If there is unknown stuff in it, how can you be sure that it should be derived from Game class? Normally the things you have not formalized enough yet, are held simply out of the diagram.
Gangnus
  • 24,044
  • 16
  • 90
  • 149
  • Sorry for the confusion, I was basically trying to create a makeshift UML diagram with only text here...Basically what my diagram intends to show is as follows (and I haven't fully learned UML diagramming conventions yet so my apologies if the diagram was misleading: basically my program will have abstract class Database has-an ArrayList abstract class VideoGameDatabase extends Database and has-an ArrayList and also has-a DatabaseNavigator(GUI) VideoGameDataBaseRecord has-a VideoGame (records of games in inventory) VideoGame can be subclassed –  Feb 25 '14 at 09:23
  • to console specific classes such as PS2Game, XBoxGame, and so on. –  Feb 25 '14 at 09:27
  • @Justin I have got this, thank you, and what do you think about the possible problems I have found? – Gangnus Feb 25 '14 at 09:37
  • Well, for starters you're absolutely right about the relationship with VideoGameDatabaseRecord and VideoGame - there should only be one VideoGame per record, that's a foolish mistake on my part. As for the free tools I tried ArgoUML and the NetBeans UML plugin but found both to be quite clunky. –  Feb 25 '14 at 09:43
  • @Justin look diagrams http://stackoverflow.com/a/22009701/715269 and http://stackoverflow.com/questions/18813549/association-owned-by-classifier-and-association-owned-by-relationship-in-uml/21550923#21550923. These are made by community VP-UML. Not ideal, but it works and is free. NetBeans UML plugin is not supported for some years already - you were brave to try it! – Gangnus Feb 25 '14 at 10:00
0

I think you've mixed logic and model views in just one diagram. Speaking of core/business logic terms, your diagram should only contains the entities Store, VideoGame... In a deeper layer your would model how to persist it, there'd you speak of database, records...

So, first your business model could be as simple as this: Logic class diagram

When you have the concepts of store, a generic sellable type, and a videogame which is concrete sellable item. In general composing is preferable over inheritance, so instead of having NintendoGame, PS2Game... as subtypes I've modelled it with a the console property.

Then it's when you persist the model (to a file, db, etc.). The thing it's that you have a separate layer in your application for this purpose. This layer will be in charge of serialize a VideoGame into a register and viceversa. You can could also have another class diagram or just having a couple of classes in charge of the IO.

ps: I don't know what's the purpose of DatabaseNavigator so I ignored in my answer.

polypiel
  • 2,321
  • 1
  • 19
  • 27
  • I made changes to this model last night, changed some things, added some interfaces and hopefully did a much better job. I posted it here, could you please take a look and let me know if the new model looks correct? [http://stackoverflow.com/questions/22046222/guidance-with-oo-design-of-my-uml-diagram](http://stackoverflow.com/questions/22046222/guidance-with-oo-design-of-my-uml-diagram) BTW the DatabaseNavigator (renamed to InventoryManager in new model) is just the UI utilizing swing components to browse records. –  Feb 26 '14 at 16:12