Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Skeleton Java Code for Class Diagram

Options
  • 09-08-2012 5:36pm
    #1
    Moderators, Education Moderators, Technology & Internet Moderators, Regional South East Moderators Posts: 24,056 Mod ✭✭✭✭


    Its been years since I did UML Data Modelling / Class Diagrams. I came across a diagram in a revision question which asked I write the skeleton java code for the Library Controller class (i.e. property type declarations only needed). Anyway, I wrote out skeleton code for the diagram but I have no solution to see if I am correct or not.

    Any thoughts?

    UMLDiagram.png
    public class LibraryController implements MembersService, BookService {
    }
    
    public interface MemberService {
    }
    

    public interface BookService {
    }
    

    public class MembersServiceImpl implements MembersService {
    }
    


    public class BookServiceImpl implements BookService {
    }
    


Comments

  • Registered Users Posts: 11,979 ✭✭✭✭Giblet


    Why is a controller implementing a service rather that taking an instance of one?


  • Moderators, Education Moderators, Technology & Internet Moderators, Regional South East Moderators Posts: 24,056 Mod ✭✭✭✭Sully


    Giblet wrote: »
    Why is a controller implementing a service rather that taking an instance of one?

    That's how the diagram goes on the sample question, just the arrow heads need adjusting but the program I used didn't seem to have the option.


  • Registered Users Posts: 880 ✭✭✭clearz


    Sully wrote: »
    just the arrow heads need adjusting but the program I used didn't seem to have the option.

    I don't usually get involved in this forum but since I'm here I'll give a crack at explaining this.

    The type of arrow used in class diagrams are of huge importance in determining the type of relationship between classes.
    I would bet my left kidney that you changed the type of arrows leading from the controller class from an association type to a generalisation type changing the semantics in the process. If we are to use an associative relationship between the LibraryController and the two interfaces MemberService and BookService then the code for the LibraryController class would be as follows.

    [PHP]
    public class LibraryController {
    private MemberService memberService;
    private BookService bookService;
    }
    [/PHP]

    The rest of the classes look correct.


  • Moderators, Education Moderators, Technology & Internet Moderators, Regional South East Moderators Posts: 24,056 Mod ✭✭✭✭Sully


    Scan of the diagram attached.

    Example_thumb.jpg


  • Moderators, Technology & Internet Moderators Posts: 1,334 Mod ✭✭✭✭croo


    Umbrello and ArgoUML are two open source UML modelling apps that will generate the code (java, c++ and more)... as well as having the "right arrow heads"


  • Advertisement
  • Moderators, Science, Health & Environment Moderators, Social & Fun Moderators, Society & Culture Moderators Posts: 60,092 Mod ✭✭✭✭Tar.Aldarion


    Sully wrote: »
    Scan of the diagram attached.

    Example_thumb.jpg

    I think those two are association arrows as said above, making your code correct if you take into account clearz changes. Although so many of them are similar, it confuses me. Thought dotted lines were dependencies too...

    Edit: this seems handy http://stackoverflow.com/questions/1874049/uml-arrows-pointers-explanation


Advertisement