Results 1 to 7 of 7

Thread: Design question for DAO interface

  1. #1

    Default Design question for DAO interface

    Hi@all,

    i'm designing some Service and DAO interfaces for my application at the moment and i'm not sure if it is better to include full domain objects in the signatures or only the identifiers (in my case a long type).

    For example:

    variant a):
    Code:
    public void changeRequestStatus(Request request, Status status);
    variant b):
    Code:
    public void changeRequestStatus(long requestId, Status status);
    Status is an enumeration and Request my domain object.

    What is considered the better design?
    Thx in advance!
    -lasse

  2. #2

    Default

    Assuming both variants are thought for DAO and not for "Service" also assuming Request is a domain object and not a DTO, If I were you, I would think about how much of Request do I need?

  3. #3

    Default

    Quote Originally Posted by lasse_stromberg View Post
    Hi@all,

    i'm designing some Service and DAO interfaces for my application at the moment and i'm not sure if it is better to include full domain objects in the signatures or only the identifiers (in my case a long type).

    For example:

    variant a):
    Code:
    public void changeRequestStatus(Request request, Status status);
    variant b):
    Code:
    public void changeRequestStatus(long requestId, Status status);
    Status is an enumeration and Request my domain object.

    What is considered the better design?
    Thx in advance!
    -lasse
    There is no better design, just pass what you need : the request id (it's a new request) or the whole request object (there is already an existing request and your service need it to perform its operations).

  4. #4
    Join Date
    Aug 2004
    Location
    Burgas, Bulgaria
    Posts
    37

    Default

    be flexible. if Request is a domain object with a getId() method:
    Code:
    public void changeRequestStatus(Request request, Status status) {
        changeRequestStatus(request.getId(), status);
    }
    
    public void changeRequestStatus(long requestId, Status status) {
     ....
    }

  5. #5
    Join Date
    Oct 2004
    Location
    Herndon, VA, US
    Posts
    648

    Default

    There are a few factors you might want to consider before making this decision, e.g.:
    1. Will the service be exposed remotely?
    2. Does concurrent modifications to this domain object happen very often? What kind of locking/isolation mechanism are you using?
    3. (If you are using hibernate) are you using OpenSessionInView?
    4. In a typical usage scenario, how likely/unlikely the client code would have anyway already gotten hold of an instance of the domain object at the point of invoking this service?
    5. In order to change the status, would the implementation of this service only need an id (e.g. executing a direct JDBC update)? Or would it always need a full instance (e.g. updating through an ORM tool)?
    --Jing Xue

  6. #6
    Join Date
    Nov 2005
    Posts
    112

    Default

    After looking at all these responses you would have realized that there's no 1 answer. But if you ask me, usually i would pass in the Request itself. This is because its difficult to predict what all i would need in the near future from the Request. Passing in the object helps prevent frequent changes to the method signature. For ex in this case, you might want to know what the current status is, before you allow a new status to be set etc...

  7. #7
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote Originally Posted by sabarish View Post
    After looking at all these responses you would have realized that there's no 1 answer. But if you ask me, usually i would pass in the Request itself. This is because its difficult to predict what all i would need in the near future from the Request. Passing in the object helps prevent frequent changes to the method signature. For ex in this case, you might want to know what the current status is, before you allow a new status to be set etc...
    I agree in part. I would sooner pass the object down if its there, but if there are situations where I don't have an instance, its always a pain if you have to fetch one just to pass it in. Also I would also say it depends what the object is, if we were talking about a HttpRequest or something of that ilk and littering the code with it, because I need the sessionId its not a good idea.
    Last edited by karldmoore; Nov 13th, 2006 at 02:08 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •