objectoopdesign-patternsvalue-objects

Business logic inside of value object


I think value object should not have business logic.

That maybe confused other programmers.

for exmaple,

public class PersonVO {

    private String name;
    private int age;

    public void somethingBusinessLogic() {
        // Do very complecated logic -> Using Reflection, Conversion
    }
    
}

If i use this VO, have to look vo logic how to work.

many of programmers put their business logic inside of VO.

I wonder what is best practice?


Solution

  • It depends on what architecture you are using in application. If you have layered architecture:

    Read more about other architectures here in this beautiful answer