Caught Using Inheritance!

don’t fall off your chairs…

re: ” I have in the past had long debates over whether or not the domain

object should know about persistence at all.” (Agile Modeling forum)

but i have *successfully abused inheritance* in the past to achieve an

interesting mix (for thin client/web apps).

  • Xyz Domain Class
    • can live on server or client
    • has the usual: properties and accessors
    • business methods
    • associations to other objects
    • often employs lazy loading
    • knows NOTHING about DBs
  • Xyz Business Class
    • INHERITS from the Domain Class
      • Gets all of the class properties that way 🙂
    • Knows about persistence classed (DGs/DAOs)
    • has the persistent ID
    • can get itself from the DB via an ID
    • can save() itself to DB
  • Xyz Transfer Object
    • small thing to meet some need of going between UI and server
    • used typically when the Domain Object is too big and you

      want specialized sets of properties filled in

  • Xyz Identifier Class
    • really tiny thing
    • usually just an ID and a string
    • sometimes a few other things
    • used for lightweight lists of associated classes
      • to drive drop-downs
      • typically used in conjunction with lazy loading

<gulp> there, i’ve confessed.