2

I have Status

 public final class Status {

        private int code;

        public Status(int code) {
            this.code = code;
        }

        public int getCode() {
            return code;
        }
    }

It seems that Status can be Value Object because two statuses with same code are same statuses, but Status can be added by admins, a list of statuses should be shown in the user interface;

To provide list of statuses with their names in user interface, I have additional wrapper class

public final class AvailableStatuses {
    private Status status;
    private String name;

    ...
}

public AvailableStatusesRepository {
    ...
}

What do you think about this design? Should I adjust it and make a Status as Entity and put Name field in it?

Teimuraz
  • 8,795
  • 5
  • 35
  • 62
  • I don't understand your `Currency` class. Example: What is currency 124? Or are the code values ISO codes, where 124 is Canadian dollar (`CAD`)? If so, why have separate `Currency` and `AvailableCurrency`? Why not just have entity `Currency` with internal ID, ISO number, ISO code, and description, maintainable through the UI? – Andreas Dec 11 '16 at 10:23
  • code is an internal representation of currencies, 1 - USD, 2-EUR, etc.. for this I use AvailableCurrency wrapper. – Teimuraz Dec 11 '16 at 10:32
  • @Andreas, I have changed a question little bit, instead of Currency, I changed a concept to Status, I think it will more clearly reflect my confusion. – Teimuraz Dec 11 '16 at 10:38

3 Answers3

2

The simple answer with your current design would be that AvailableStatus is an entity while Status is a Value Object (VO) which is basically a wrapper for an AvailableStatus's identity (it's code).

Your model is probably just fine as is, but one thing that you should realize is that you were forced to come up with different names, one to describe the entity and one to describe the VO.

That is because you are perhaps lacking proper Bounded Contexts (BC). You could have a maintenance/administration/settings BC where Status would be an entity while it would be a VO in any downstream contexts.

plalx
  • 42,889
  • 6
  • 74
  • 90
0

That should be a value object because it is used as descriptor for elements in your model. They are defined by their attributes and their attributes (ie. Status) determine their identity.

alltej
  • 6,787
  • 10
  • 46
  • 87
  • thanks for answer. So is it ok I wrapped Status object into AvaliableStatus and use repository like in my example? (I need to provide list of statuses in the user interface, allow admin to manage status list, etc). – Teimuraz Dec 12 '16 at 16:06
  • can your status constructor take the integer code and the string name? – alltej Dec 12 '16 at 16:28
  • this is just a suggestion to make your status code and name a read-only property which is set at the constructor. – alltej Dec 12 '16 at 17:38
  • in this case two statuses are equal if both id and names are equal. So code=1, Name="Active" and code=1, Name="Inactive" - treat them as two different statuses? – Teimuraz Dec 12 '16 at 20:21
  • even more, what if I decide to correct name of the status, let's say, from 'Active' to 'Activated', or first time I made a syntax error in status name, 'Activ'. Then, if Status is Value Object, that means that Status (code=1, name=Activ) is not equal to Status(code=1, name=Active).. – Teimuraz Dec 13 '16 at 09:34
  • Value objects are immutable. It describes the entity's state. Let's say a BankAccount, you would certainly need to look up a BankAccount by it's ID. But you would not look up it's status by its ID. The status has no meaning in isolation. – alltej Dec 13 '16 at 12:58
0

Status is a value object, and should include the name not just the ID. Both fields are immutable in the context of use (i.e., no item that has a Status field can change a Status object). The wrapper class is unnecessary.

In the context of your Admin application, Status may be treated as an Entity, with the caveat that the ID once assigned cannot be altered (which is not an unusual requirement for an Entity with a synthetic ID key)

Steven A. Lowe
  • 60,273
  • 18
  • 132
  • 202