Adding domain objects

Hello,
I'm working with an application where we have many, many, many domain objects that could be added to a "header". In my business/service interface I don't like to write 50+ of addX(...), addY(...), addZ(...) etc. methods.
Every domain object extends a domain object base class. In my business/service interface I've added one single method for adding domain objects to make the interface somewhat smaller:
public void add(DomainObject[] someDomainObjects);
    ...The elements of the domain object array are of different kind, but all extends the domain object base class. I'd like to implement class and method that have a strategy for determining what kind of domain object the current one is in the given array and invoke the correct add(...) method for that particular domain object.
The most simple way of doing it is to have a very big if-else using instanceof to determine what kind of domain object it is, but it doesn't feel like a very nice design.
Example:
public class MyBusinessObject {
    public void add(DomainObject[] someDomainObjects) {
        // Iterate over all domain objects in the array
        for (DomainObject domainObject : someDomainObjects) {
            // Determine what kind of domain object it is and create the correct DAO
            if (domainObject instanceof X) {
                DomainObjectXDao xDao = new DomainObjectXDao();
                // Save the current domain object
                xDao.save((X) domainObject);
            } else if (domainObject instanceof Y) {
                DomainObjectYDao yDao = new DomainObjectYDao();
                // Save the current domain object
                yDao.save((Y) domainObject);
            } else if (domainObject instanceof Z) {
                DomainObjectZDao zDao = new DomainObjectZDao();
                // Save the current domain object
                zDao.save((Z) domainObject);
            } else if (...) {
}Is there any design pattern for making this a more nice design?
If anyone could contribute with their good knowledge I'd be very glad!
Regards, Andreas Eriksson

Map the DomainObject types to their respective DAOs and look them up as you loop through them in the add method, e.g.:
public class MyBusinessObject {
  private Map daos = new HashMap();
    daos.put(X.class, new XDomainTypeDAO());
    daos.put(Y.class, new YDomainTypeDAO());
    daos.put(Z.class, new ZDomainTypeDAO());
  public void add(DomainObject[] objs) {
    for (DomainObject obj : objs) {
      Class type = obj.getClass();
      DAO dao = (DAO) daos.get(type);
      if (dao == null) {
        throw new IllegalArgumentException(
          "No DAO configured for DomainObject type " + type);
      dao.save((DomainObject) obj);
}You'd have to create a DAO interface (or abstract base class) which defines a save method with the signature public void save(DomainObject obj). Then each DAO would have to implement this method and cast the passed domain object to the expected type.
To take things further, you could introduce a DAOProvider interface to hide where the MyBusinessObject obtains the DAOs from (rather than have it maintain the map), e.g.:
public interface DAOProvider {
  DAO daoFor(Class domainType);
// A really simple implementation - assmes that DAOs are thread-safe
public class SimpleDAOProvider implements DAOProvider {
  private Map daos = new HashMap();
    daos.put(X.class, new XDomainTypeDAO());
    daos.put(Y.class, new YDomainTypeDAO());
    daos.put(Z.class, new ZDomainTypeDAO());
  public DAO daoFor(Class domainType) {
     DAO dao = (DAO) daos.get(type);
     if (dao == null) {
       throw new IllegalArgumentException(
         "No DAO configured for DomainObject type " + domainType);
    return dao;
}The advantage of this is you can alter the strategy for handing out DAOs, e.g. pass the same instance back each time, or dynamically instantiate a new instance, etc. Of course, you need a way for the MyBusinessObject to get hold of a DAOProvider instance (inject it? Have it use a factory?)

Similar Messages

  • Annotation Agnostic Domain Objects

    Hi,
    I would like to know how we create annotation agnostic domain objects. At present, i have to DPL annotations in my domain object for persisting in BDB. Siince, i will be sharing
    the domain objects with other projects which may or may not use BDB. So I would like to have annotation agnostic domain objects.
    Is there a way to do it in BDB? I know its possible to do it with Base API. But i would like to know whether its possible it in DPL itself.
    In BDB forums, there were some leads to use EntityModel and AnnotationModel which are not clear to use. I would like to have more example on this, if it is possible to do it by EntityModel or AnnotationModel.
    Any help on this is Highly Appreciated.
    Thanks
    William

    Hi William,
    Just to make sure I understand your question. You basically want to have plain domain objects, non-annotated (non DPL annotated) POJOs representing the domain objects, and you want to use them with JE's DPL, without adding the DPL specific annotations to persist the objects (something similar to what you would do with Hibernate's mapping documents). Correct?
    Regards,
    Andrei

  • Domain Object and Service oriented pattern

    We have J2EE based application with following components, we are facing some issues with existing system.
    Current System : We have J2EE based application. The following is the flow.
    Client Layer [including JSP, Struts ] action classes  Delegates  Session fa�ade [Session bean]  DAO EJBDAO  EJB. We use CMP, xDoclets , JBOSS.
    1.     Our Domain objects are heavy. I know they are suppose to be coarse objects but they take more time in loading. Also, we noticed one thing that lot of methods are called during Domain Object creation process and it takes lot of time in loading. Actually, we dont really know what is happening as we are using CMPs.
    Question :
    -     Any input on what can be done to avoid Domain object excessive loading time.
    -     Anyone can share there experiences with Domain objects. Are you facing issues related with performance.
    -     We dont use DTO, we pass domain objects between. Do you see any problem in doing that.
    2.     Currently, our system was used by one single front end or lets say we have only one client but soon we will have more clients using it.
    Question :
    -     What should be our design approach. How can we make our system more like service oriented. If the two clients demand different business logic then how it will be handled. Business logic common to all the clients will be handled by which layer and business logic specific to client will be handles by which layer.
    -     Please suggest based on our existing infrastructure. We don�t want to use SOAP or cannot make drastic changes to our flow.
    We have domain and services in the same package and we are doing the refactoring of code, your inputs will be valuable.
    Thanks
    Sandipan

    What type of logger do you use and what is the loger-level during production?
    If it is log4j set the logger to level INFO or WARN.
    This might sound trivia but can make a difference between 20seconds and 500 ms.

  • Error while adding the Objects in Existing DSO -Table /BIC/B* is too long ( 004030)

    Hi Team,
    We added some objects in the existing Write Optimized DSO.  while activitating the DSO We got the below error .
    Table /BIC/BXXXXXXXXX is too long (>004030)
    Please go through the issue and provide the solution.
    Thanks,
    Purushotham.

    Hi Purushotham,
    Is the table in error log is active table of DSO? it doesnt look like...it will be /BIC/A<DSO>name
    in your case it is /BIC/B----!!
    Now  instead of adding 15 fields, could you try concatenating 2 fields in 1 and in that way you will have to add 7-8 fields.
    later at Standard DSO layer or Cube layer you can read relevant field value by "field+(<No.>)"
    And you mentioned that you willtry for concatenate 4 IO of length 60 into 1 InfoObject (IO).
    This cant be done...max lenght is 60! then how will you create a IO with lenght 240! please think of other logic.
    Regards,
    Gaurav

  • Using domain object instead of generated ones?

    I'm using NetBeans, and I'm curious if there's a way that we can use our domain objects with the web service calls rather than the empty stubs generated by wsgen?
    wsgen creates the skeletal client classes, as well as an ObjectFactory that returns instances of those classes. I imagine I could modify ObjectFactory to return our domain objects instead, but then we'd be breaking with wsgen.
    Is there a better solution to this?
    Thanx!

    You can associate a Virtual Host to the loopback IP address 127.0.0.1 read about Virtual Hosts here: http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html
    But with the above configuration alone you can access your app via http://somedomainname.com only on your local machine, no one else on the internet will see it.

  • DAO and Domain Object

    hi,
    Normally when i want to persist a domain object like Customer object to a database, my statements will be below,
    // code from my facade
    Customer cust = new Customer();
    cust.setFirstName("myname");
    cust.setLastName("mylastname");
    // set another attributes
    cust.create();
    with this code i have a CustomerPersistence object to handler for create this customer record to a database. Now j2ee have a DAO pattern. So my question is,
    1.where is a domain object within DAO pattern? --> because of we can reused domain object.
    2.DTO is Domain Object, isn't it?
    3.when i look at some articles about DAO, many of it will present in this way
    facade -->create DTO --> call DAO (plus something about factory pattern)
    i never see something like this
    facade --> domain object --> dao
    any suggestion?
    anurakth
    sorry for my english!!

    Hi,
    I am a bit confused about implementation of the domain model and I wondered if you could help. My main concern is that I am introducing too many layers and data holders into the mix. Here is what I am thinking.
    DTO - used to carry data between the presentation and the services layer
    Service Class - coordinates the calling of domain objects
    Domain Object - models a domain entity, service layer logic specific to this object is to be implemented here.
    Data Object - an exact representation of a database table. many to many relationship between domain object and data object.
    Hibernate DAO Class - has no properties, just methods used for read and writing the object to the database. It is passed in the Data Object for persistence. Is it wrong that the DAO contains no properties?
    Perhaps the domain object will contain each data object it is comprised of. I was originally going to keep calls to DAOs in the Services class (as recommended in http://jroller.com/page/egervari/20050109#how_to_change_services_logic ) but I am thinking that each domain object could expose a save method, and that method would co-ordinate persisting itself to the various tables it is derived from.
    Does this sound resonable? I have trouble finding a pattern on the net that clealy defines the Domain Model. I was tempted to map Domain Objects directly to database tables, and simply persist the Domain Object, but this 1-1 relationship may not always hold true.
    Thanks.

  • Infosource -adding new objects

    I enhanced the datasource 2lis_02_itm with some objects using abap code. I created the objects in BW and replicated the datasource. I added those objects to the info source.
    Now , I am not able to assign these objects in the info source, I do not see these objects in the list.
    Thanks

    Yes I activated the cube after adding the fields.Here's what I did exactly:
    1. Wrote the abap code for 5 key figures and marked them as "selection" in the datasource.
    2. Deleted the data source assignment (I had assigned it earlier)
    3. replicated the datasource
    4. Reassigned the datasource
    5. Added the kf's to the comm structure
    6. I see them in the transfer structure but unassigned
    7. I assigned these objects in the transfer structure manually
    8. activated the info source
    9. added the kf's to the cube
    10. activated the cube
    11. I do not see them in the update rules!!!!
    Thanks

  • Help regarding Domain Object.

    Hi,
    I have a question regarding the domain object. I have a form where there some multiple entries for some fields . The domain object is return mapping to the database fields. How should the domain object be changed to handle multiple fields so that multiple inserts can be done.. Can the domain object be coded as an array type. or how the coding needs to be done..I am using JPA
    If some one knows please post it..
    Thanks,

    sahir,
    check the triggering point of your user exit.
    make sure to use a exit/BADI which triggers right after you press 'SAVE'
    thank you.

  • Adding a object to the next request

    Hi all,
    Suppose your in a JSP section at the top of your page, and later there is an html button, that will submit the form. I know you can write code such as:
        request.setAttribute("name", object);However, that attribute is set to the previous request. (Which seems mostly useless.) However, suppose I wanted the object to be added to the next request. The request when the user click the button.
    I know about hidden inputs, but I want to add actually objects to the request, not just strings. Besides, it is kind of a pain, to add a different hidden input every time you want to add an object to the next request.
    I like how session works, with session.getAttribute(name) and session.setAttribute(name, value).
    What advice do you guys have?
    Grae
    PS: See http://forums.sun.com/thread.jspa?threadID=5442963&tstart=0 for more details. I am still looking for more answers.

    It turns out hiddenInput is only for strings, not objects. I am not using tomahawk or a4j, so I can't use either of them. Do you have any other ideas?
    I was thinking of using a session scope Map, and adding the object to the map, and passing the key to the next page as hidden input. However, I am having a little trouble telling when and how to add it to the map.
    I want the object to accept input from the gui, and then be saved. Basically, I think I need to grab the object at a phase after the data is added to the object, but before the object it deleted. I don't know a lot of the phase listeners, so I am not sure how to do what I want to do.
    Do you have any ideas how I would do that, or a better way to do the same thing?
    Grae

  • Bean vs Domain Object Responsibility

    Any thoughts out there regarding the decision point on when to put functionality into a domain object (Customer, Order, Address, etc.) versus when to put it into an EJB that you plan to use? You usually start defining your object model and as you create sequence diagrams or collab. diagrams, you begin assigning methods to the classes. But at what point do you decide that functionality does NOT belong in the domain object and instead belongs outside of that object? EJBs have the ability to perform a lot of the work in an N-Tier system, so how do you draw the line on where the functionality goes? Any articles on the subject?
    Thnx.
    Dave

    Any thoughts out there regarding the decision point on
    when to put functionality into a domain object
    (Customer, Order, Address, etc.) versus when to put it
    into an EJB that you plan to use? When you need to access system resources, like connecting to the database, you may place the functionality in EJB. When you need to perform task of processing the domain object related information like the net purchase of the customer then you place the functionality in the domain object.
    You usually start
    defining your object model and as you create sequence
    diagrams or collab. diagrams, you begin assigning
    methods to the classes. But at what point do you
    decide that functionality does NOT belong in the
    domain object and instead belongs outside of that
    object? EJBs have the ability to perform a lot of the
    work in an N-Tier system, so how do you draw the line
    on where the functionality goes? Any articles on the
    subject?
    Thnx.
    DaveThats my opinion.
    Best Regards,
    Amitabh Choudhury.

  • Manually added Authorization object

    All ,
    What is the impact for manually added authorization objects in the roles after the system upgrade??

    My 2 cents, since I don't see any replies.
    I try to avoid manual auth objects on a role as much as possible.  One problem with manually auth object is in PFCG, it will not give a reference to what transaction the auth object came from.  Unless thoroughly documented this can be an audit issue. 
    In regards to upgrades, I don't this it will have any affect.  It is usually the tcodes that are affected.

  • Manually added auth objects and Derived roles

    If there are manually added auth objects in the parent role do they come across to the derived roles?
    Also if you manually added auth objects into a derived role will they be overwritten by the parent role if you auto derive from the parent role?

    yes, any auth objects will come across to derived roles when you click 'generate derived roles'  from your parent role. basically its copying your parent role authorizations to derived roles  except org. level data( if you had maintained them thru 'org. maintainence' button and not adding in individual objects).
    yes. manually added auth objects in your derived roles will be overwritten by the parent role authorizations when you click 'generate derived roles'  from your parent role.
    if you just derived the role menu and din't copy the authorizations(generate derived roles) then there will not be any interlink between the parent and derived roles for authorizations.
    http://help.sap.com/erp2005_ehp_02/helpdata/en/1c/c38028816c11d396bc0000e82de14a/content.htm

  • What is a Domain Object?

    I checked dozens of internet pages but didn't find an answer on that question.

    Domain is everything meaningful in the scope of
    current task, thus domain object is an abstraction of
    the real or imaginable entity from the scope of
    current task.Can you please give me an example?
    I will now explain a little bit why I am asking. But please don't forget to give me an example.
    We use the root object as a domain object. "Article" is a domain object in our company. An Article has a 1:m relationship with a "PackageUnit". The PackageUnit is no domain object. Furthermore the PackageUnit has a 1:m relationship with SalesHistoryWeek (which is no domain object too) and so on.
    Only the domain object (Article) can create new instances of the objects which are linked to it (PackageUnit and so on). A PackageUnit cannot create a new instance of SalesHistoryWeek, only Article can do this, the domain object.
    Furthermore only the domain object has getter and setter methods for the linked non domain objects. So the domain object "jumps" over many knots to get or set an object.
    I think this is a strange design and so I am asking here for the meaning of domain objects. Besides this, the coupling of objects is very large in my example and it doesn't respect the Law of Demeter.
    What do you think?

  • Domain object

    Hello!
    I use Spring back-end layer, when I communicate domain
    objects(Flex - Java), on the server I have zero in int, double
    fields, on the client this fields are declared as int and Number.
    Only String type transfer correctly!!!
    How I can resolve this problem?
    //Flex d-o
    [Bindable]
    [RemoteClass(alias="com.home.flex.bean.GoodsBN")]
    public class Goods
    public var idGoods:int;
    public var code:int;
    public var name:String;
    public var weight:int;
    public var type:String;
    public var category:String;
    public var incomeDate:Date;
    public var description:String;
    public var price:Number;
    public function Goods()
    //Java d-o
    public class GoodsBN //implements Serializable
    private int idGoods;
    private int code;
    private String name;
    private int weight;
    private String type;
    private String category;
    private Date incomeDate;
    private String description;
    private double price;
    public GoodsBN()
    ///getter and setter.....

    "vscmaster" <[email protected]> wrote in
    message
    news:gii9eo$4dl$[email protected]..
    > Hello!
    > I use Spring back-end layer, when I communicate domain
    objects(Flex -
    > Java),
    > on the server I have zero in int, double fields, on the
    client this fields
    > are
    > declared as int and Number.
    >
    > Only String type transfer correctly!!!
    >
    > How I can resolve this problem?
    I think Number _is_ the AS3 equivalent of Double

  • Shoul I have my backing beans extend my domain objects?

    Hi,
    In our JSF application, most of our backing beans have the same properties that a corresponding domain object.
    In order to have a clear separation between layers, we have a set of view objects and a separate set of domain objects. Once we populate the backing bean, we copy the value of properties to the domain object.
    Since all the properties of my domain object are duplicated in my backing beans, we were wondering if it is a good (or bad) idea to extend (inherit) my backing beans from my domain objects, and pass the backing beans to my persistence and business layers. This will save us some work.
    Thanks a lot for the advice.
    Mauricio L.

    I think I've solved my own issue though I'm not sure if it is the correct way to accomplish the task at hand.
    When the button for login is clicked and the logginButton_action() method is called inside of my login_jsp_backing class I do the following:
    User user = new User();
    FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("User", user);
    return user.doLogin(this.getInputUsername().getValue().toString(), this.getInputPassword().getValue().toString());
    (The String return of this method in User is a navigation rule I've setup in my faces-config)
    So my new question is that "Is this best practice?" or should I be doing it differently?
    Message was edited by:
    Steve Carlson

Maybe you are looking for