3 Replies Latest reply: Mar 11, 2010 12:42 PM by jschellSomeoneStoleMyAlias RSS

    Share a base class or to not share?

    843853
      Hey,

      I have entity type category and another entity type - logisitchierarchy.
      From the business prespecive they have nothing in common.
      From the structre prespective - they both have a tree (hierarchy structre - parent - childs) - so they share "structre functionality" like calculate path , get root and etc.


      if for each i write the structre and they not share the same base, fix for the base structre - for example you discover that the best way to model tree is with addtional column for calculate-path..., will required to fix it in all "trees structre" in the application.

      in addtional base class for all make it easier to share structre functionalty.

      what is your opinion - does common structre (a one that required complex functuionality) are a good reason to inherit from the same class?
        • 1. Re: Share a base class or to not share?
          jschellSomeoneStoleMyAlias
          avihai wrote:
          what is your opinion - does common structre (a one that required complex functuionality) are a good reason to inherit from the same class?
          Absolutely not.

          If you have shared code then you can implement that as separate class which you use via composition. The form of that class can vary but it might have only static methods.

          However be careful to insure that the code is in fact actually shared. If you need to add flags to define significantly different execution paths then the fact the code is similar doesn't mean it is the same. And thus it should not be shared at all.
          • 2. Re: Share a base class or to not share?
            843853
            I defiantly agreed that you don't suppose to share class due to structure reuse,but in this case the class is a model (JPA), so if you don't share the base class and share functionality by composition you are lose using in same prepared-statement/dao mechanism and you need to create prepared-statement for each impel, but any way i still agree with you.
            • 3. Re: Share a base class or to not share?
              jschellSomeoneStoleMyAlias
              avihai wrote:
              I defiantly agreed that you don't suppose to share class due to structure reuse,but in this case the class is a model (JPA),
              Which is the first time you mentioned JPA.
              so if you don't share the base class and share functionality by composition you are lose using in same prepared-statement/dao mechanism and you need to create prepared-statement for each impel, but any way i still agree with you.
              That makes no sense. If you are using persistence that is required then how can it not share data (not behavior)?

              But regardless, you still do not derive solely for convienence.