Determining UseCase vs Attribute

Discussions

EJB design: Determining UseCase vs Attribute

  1. Determining UseCase vs Attribute (1 messages)

    I posted this question as a response to another post, but thought maybe it deserved its own discussion.

    I am having a lot of trouble determining when a piece of data in relation to a domain object is an attribute and when it is a UseCase. For example, consider the example of two domain objects Company and Address.

    Generally in pure OO terms, this relationships would be defined with an addresses:Address attribute on the Company object. To add a new address, a client would normally get the appropriate Company and then do company.getAddresses().add( newAddress ).

    However, J2EE seems (I am new to J2EE, so this is my early impression) to want you to instead define seperate CompanyDTO and AddressDTO objects for use by the client where CompanyDTO would not have an addresses attribute. To then add a new relationship you would then add a UseCase method on a SessionFacade object like: customerCatalog.addAddressToCompany( company, address ) which would then set the relationship appropriately on the domain objects (as well as perform any other related activities).

    So my question is: when should a data relation that would normally be defined as an attribute in OO design be refactored out into a SessionFacade method in a J2EE design? What are the best practices which define when that should happen?

    Hopefully this makes sense...
  2. Hi,

    I think you have issues around the concepts of DTO's, use-cases and domain/entity objects.

    Your use case is to add an address to a company. An example call into the facade to model this would look something like this,

    AddAddressResponseDTO customerCatalog.addAddressToCompany( companyID, addressRequestDTO)

    companyId is the unique id that refers to the company, addressRequestDTO is an object that contains all the info needed to add the address and AddAddressResponseDTO is an object that contains the information required by the client after the call is made.

    Inside your session facade you use the method paramters to make the appropriate changes to you domain model and do any other work you need to do. Your domain model could be implemented in a number of ways ie Entity Beans, JDO's etc.

    Hope this helps,
    David