Note that there are some explanatory texts on larger screens.

plurals
  1. PONovel / Book Object Oriented Design Approach
    primarykey
    data
    text
    <p>I am creating an object oriented representation of a novel or book. I am looking for design patterns or advice in terms of what to make an object, and what to make an attribute of another object.</p> <p>For example, suppose I'm interested in the characters in the novel, and which chapters and pages they appear on.</p> <p>The concept I'm struggling with is how to organize an object system with two types of "containers" that both participate in relationships with the same instances. I imagine this comes up in other systems where there is a metaphorical "physical" and a "logical" view of the underlying data.</p> <p>There are a variety possible objects here: Novel, Chapter, Page, Character.</p> <p>There are a variety of relationships between these possible objects:</p> <ul> <li>Novels have a sequence of Chapters, a sequence of Pages, and a collection of Characters</li> <li>Chapters have a sequence of Pages, and a collection of zero or more Characters</li> <li>Pages are associated with one or more Chapters, and zero or more Characters</li> <li>Characters are associated with one or more Pages and Chapters</li> </ul> <p>The purpose of these objects would be to answer questions like:</p> <ul> <li>What pages does character Alice appear on?</li> <li>What characters appear in chapter 6?</li> <li>Which characters frequently appear on the same pages?</li> <li>What page is character Bob mentioned for the first time on?</li> </ul> <p>I'm a bit lost as to how to approach this sort of design. I see a few approaches:</p> <ul> <li><p>Make everything (Novel, Chapter, Page, Character) an object, and each of these objects has lists of references to other objects they contain / relate to</p></li> <li><p>Give primacy to one or the other of Chapter or Page, and make the other an attribute of the first. For example we could go with just a Novel, Chapter, and Character object list, and make "pages" an attribute of the Chapter object.</p></li> <li><p>We could take the above idea even further and just stick with Novel and Character, and give each Character a few attributes such as: "Occurs in Chapter" and "Occurs on Pages"</p> <p>Well, I hope that's clear enough for some OO design gurus to suggest where to draw the line between Object or Attribute, and how to design an object system where there are different kinds of containers (Chapter, Page) that the objects of interest (Character) belong to.</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload