Ex10 - Problem with Header, Footer and DocType declaration

L4_
BASIC-Programmierer
BASIC-Programmierer
Beiträge: 104
Registriert: 24. Apr 2012 15:44

Ex10 - Problem with Header, Footer and DocType declaration

Beitrag von L4_ »

Hello,

related to the template file, the abstract class HTMLBuilder is calling "addHeader()" in line 6.
(which means, when a subclass of HTMLBuilder gets constructed, that method will be called)

First, I guessed to implement the "addHeader()" in the subclasses to add the DocType string to the builder.
But then several questions came up in my mind:

1. Shouldn't there be the methods "addDocType()" and "addBody()" which are called analogous to "addHeader()"? This would mean I have to change the template class HTMLBuilder.
2. In the Ex10 document, there is no "footer" mentioned. What do you expect us to do with "addFooter()" anyway or did I miss something?
3. Whenever the client would build an HTMLDocument with any DocumentBuilder, are they able to add elements explicitly in the head-scope and/or body-scope? As far as I can see, there is no way because the SourceCodeBuilder only allows to append strings in the end.

Update1:
For 1. and 2. I think I got an idea but as you can see, at first it confused me.
I think if the methods "addHeader" and "addFooter" were called "startBuilder" and "endBuilder" or something like that it might be more clear to understand that every incoming markup (that we want to add to the builder) gets inbetween the "<body>" ... "</body>".
But there also comes up a question:

4. Should we consider the case that if we get the result of an HTMLBuilder that I might want to add any more elements?
For example, I call "result" of an HTMLBuilder-object and lets say "addFooter()" adds "</body>" to the SourceCodeBuilder to finish the code properly.
Now if I decide to add more elements to the same HTMLBuilder-object and get the result again, it would contain two times "</body>" which would not be proper.

Kind regards

imaier
Mausschubser
Mausschubser
Beiträge: 61
Registriert: 21. Okt 2013 21:27

Re: Ex10 - Problem with Header, Footer and DocType declarati

Beitrag von imaier »

I agree that the names for addHeader and addFooter might not be the most fortunate ones, but I see that you figured it out already.

Concerning adding elements to the header, you do not need this in this exercise.

For the result methods, they should return the results and are allowed to "close" the builder, i.e., once clients call result, they are not allowed to use the given builder any longer. This is a common pattern for builders.

Cheers,
Ingo

Antworten

Zurück zu „Archiv“