Skip to main content
added field and class names as requested in comments
Source Link
                        +------------------+
                        |     ObjectA  NoteMapping    |
                        |------------------|
                        | String one   noteId    |
                        | String two    content   |
                        |                  |
                        +---------+--------+
                                  |
                  +---------------+----------------+
                  |                                |
         +--------|--------+              +--------|--------+
         |     ObjectAAUserNote    |              |    ObjectAB AdminNote    |
         |-----------------|              |-----------------|
         | String three userId   |              | String four   adminId  |
         |                 |              |                 |
         +--------+--------+              +--------+--------+
                  |                                |
                  |                                |
         +--------|--------+              +--------|--------+
         |   ObjectAAA  UserBookNote   |              |    ObjectABA  AdminBookNote  |
         |-----------------|              |-----------------|
         | String five  bookId   |              | String five  bookId   |
         |                 |              |                 |
         +-----------------+              +-----------------+

ASCII tables drawn using http://www.asciiflow.com/

Edit

I have added some class and field names to the class diagram above.

The reason bookId cannot exist in any of the parent classes is because it is used to create a OneToOne relationship with another class - which is not something that we always want to do.

                        +------------------+
                        |     ObjectA      |
                        |------------------|
                        | String one       |
                        | String two       |
                        |                  |
                        +---------+--------+
                                  |
                  +---------------+----------------+
                  |                                |
         +--------|--------+              +--------|--------+
         |     ObjectAA    |              |    ObjectAB     |
         |-----------------|              |-----------------|
         | String three    |              | String four     |
         |                 |              |                 |
         +--------+--------+              +--------+--------+
                  |                                |
                  |                                |
         +--------|--------+              +--------|--------+
         |   ObjectAAA     |              |    ObjectABA    |
         |-----------------|              |-----------------|
         | String five     |              | String five     |
         |                 |              |                 |
         +-----------------+              +-----------------+

ASCII tables drawn using http://www.asciiflow.com/

                        +------------------+
                        |   NoteMapping    |
                        |------------------|
                        | String noteId    |
                        | String content   |
                        |                  |
                        +---------+--------+
                                  |
                  +---------------+----------------+
                  |                                |
         +--------|--------+              +--------|--------+
         |     UserNote    |              |    AdminNote    |
         |-----------------|              |-----------------|
         | String userId   |              | String adminId  |
         |                 |              |                 |
         +--------+--------+              +--------+--------+
                  |                                |
                  |                                |
         +--------|--------+              +--------|--------+
         |  UserBookNote   |              |  AdminBookNote  |
         |-----------------|              |-----------------|
         | String bookId   |              | String bookId   |
         |                 |              |                 |
         +-----------------+              +-----------------+

ASCII tables drawn using http://www.asciiflow.com/

Edit

I have added some class and field names to the class diagram above.

The reason bookId cannot exist in any of the parent classes is because it is used to create a OneToOne relationship with another class - which is not something that we always want to do.

Source Link

OOD: All classes at bottom of hierarchy contain the same field

I am creating a class diagram for what I thought was a fairly simple problem. However, when I get to the bottom of the hierarchy, all of the classes only contain one field and it is the same one.

This to me looks very wrong, but this field does not belong in any of the parent classes. I was wondering if there are any suggested design patterns in a situation like this?

A simplified version of the class diagram can be found below.

Note, fields named differently cannot belong to any other class

                        +------------------+
                        |     ObjectA      |
                        |------------------|
                        | String one       |
                        | String two       |
                        |                  |
                        +---------+--------+
                                  |
                  +---------------+----------------+
                  |                                |
         +--------|--------+              +--------|--------+
         |     ObjectAA    |              |    ObjectAB     |
         |-----------------|              |-----------------|
         | String three    |              | String four     |
         |                 |              |                 |
         +--------+--------+              +--------+--------+
                  |                                |
                  |                                |
         +--------|--------+              +--------|--------+
         |   ObjectAAA     |              |    ObjectABA    |
         |-----------------|              |-----------------|
         | String five     |              | String five     |
         |                 |              |                 |
         +-----------------+              +-----------------+

ASCII tables drawn using http://www.asciiflow.com/