I have some 3 layers which are connected by parent - child - sub-child as compositions. Where the child element depends on the upper parent element (and is destroyed when parent is destroyed). Like a book, which has several pages, which has several words. How do i model this correctly? I want to create them from the inside to outside and the best is to add the 2 childs as a list to the respective parent object.
class Book:
def __init__(self, bookName):
self.bookName = bookName
self.listOfPageObjects = []
class Page(Book):
pageBackColor = "white"
def __init__(self, bookName, numberOfWords, pageNumber):
super().__init__(bookName)
self.numberOfWords = numberOfWords
self.pageNumber = pageNumber
self.listOfWordObjects = []
class Word(Page):
wordFont = "courier"
wordMaxLen = 100
def __init__(self, bookName, numberOfWords, pageNumber, actualWord):
super().__init__(bookName, numberOfWords, pageNumber)
self.actualWord = actualWord
Would this be the ideal way to do that?