oop - The correct class hierarchy -


in general case have following document types:

  • document header part (сlass documentheader)
  • document header , detail parts (сlass documentdetail)

both classes abstract , need inherit them in order realize required functionality:

  • сlass documentheader {}
  • class documentdetail : documentheader {}

next, have concrete documents:

  • consolidated order. contains consolidated data order (class order)
  • detailed order. contains consolidated data , table part detail ordered products (class orderdetail)

so, have problem:

detailed order should inherit functionality consolidated order:

  • class orderdetail : order {}

both detailed , consolidated orders should inherit abstract classes:

  • class order : documentheader {}
  • class orderdetail : documentdetail {}

please give idea, how realize that. thanks!

i think should consider composition

psuedo-ish code like

class cdocument {   public:     cdocument ( idocumentheader header, idocumentdetails details ) :        this.header(header), this.details(details) {}      idocumentheader getheader() { return header; }     idocumentdetails getdetails() { return details; }    private:     idocumentheader header;     idocumentdetails details; }; 

not entirely sure on order/order detail relationship, have order cdocument, contains documentheader implementation , orderdetail implementation of documentdetails.

class cdocumentheader : idocumentheader{};  class corderdetail : idocumentdetail{};  void whatever() {   cdocument order ( new documentheader(), new orderdetail() ); } 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -