Factory Method
1. Are the create functions in the Document interface Factory Methods?
2. What are some of the other Products in the DOM example that are amenable to Factory Method?
3. Why use a Factory Method instead of a statement like “new MazeRoom;”?
"Any problem in computer science can be solved with another layer of indirection."—David Wheeler (chief programmer for the EDSAC project in the early 1950s)
1. How does Factory Method introduce indirection?
2. What problem does the indirection solve?
4. How does Factory Method promote loosely coupled code?
5. Does having a parameterized Factory Method not eliminate the advantage of hiding the ConcreteCreator?
6. Who creates the appropriate Factory Method concrete class? How does Factory Method not just push the problem that it is solving back one step?
7. Factory Method’s appear commonly in frameworks. What are two ways that the Factory Method is used in this context?
8. Where might Factory Methods be used outside of a framework?
9. Can Fowler’s refactoring “Replace Constructor with Factory Method” be applied in the DOM example?

1. Is XMLTokenizer.XMLToken a Strategy class?
2. When the book discusses the applicability of Strategy it says that one use is to remove many conditional statements by putting each block in a concrete Strategy.
1. What conditional statements are removed in the assignment?
2. How does this reduce coupling?
3. What potential problem does this usage introduce for Strategy if there are multiple conditions being checked?
3. How do you configure the context with the correct Concrete Strategy?
4. The Concrete Strategy can be configured dynamically by some other part of the program. What you are hiding from one part of the program doesn’t necessarily need to be hidden from other parts of the program. In the implementation section of this pattern, the authors describe two ways in which a strategy can get the information it needs to do its job. One way describes how the strategy could get passed a reference to the context object, thereby giving it access to the context data. But is it possible the data will not be available from the context’s interface? How could you remedy this potential problem?
5. What is the lifetime of a concrete Strategy?
6. Can a concrete Strategy be shared between different Context objects?

1. Is Node the best interface in the hierarchy to Decorate, or would a different one work better?
2. A decorator object’s interface must conform to the object that it decorates. Now consider an object A that is decorated with an object B. Since object B “decorates” object A, object B shares an interface with object A. If some client is then passed an instance of this decorated object, and that method attempts to call a method on B that is not part of A’s interface, does this mean that the object is no longer a Decorator in the strict sense of the pattern?
3. Furthermore why is it important that a decorator object’s interface conforms to the interface of the component that it decorates?
4. What further requirement is there on Decorators (and Proxies and Strategies) than just conforming to the interface in order to make them work in place of the original object?
5. What makes this pattern structural instead of behavioral, or vice versa for Strategy?
6. Who decorates objects?
b. How is the exercise implementation of Schema/DTD validation different from a traditional implementation? Is this good or bad?
c. The main or test function in my implementation of XMLValidator needs to explicitly construct decorated objects. What other pattern-based refinement can we add to the implementation to minimize this and make the Decorator version of validation look almost like the XMLSerializer test?

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

Factory Method
1. Are the create functions in the Document interface Factory Methods?
• Yes, they do, for Document is a DOM interface
• Factory Methods define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
• In the DOM Level 1, objects implementing some interface "X" are created by a "createX()" method on the Document interface; this is because all DOM objects live in the context of a specific Document. Most objects can be built from the Create methods on Document

2. What are some of the other Products in the DOM example that are amenable to Factory Method?
• We note that objects created by the factory are called products. A factory is a class containing one or more factory method
• All DOM interfaces use factory method. They are :
1. Attr
2. CharacterData
3. ChildNode
4. Comment
5. CustomEvent
6. Document
7. DocumentFragment
8. DocumentType
9. DOMError
10. DOMException
11. DOMImplementation
12. DOMString
13. DOMTimeStamp
14. DOMSettableTokenList
15. DOMStringList
16. DOMTokenList
17. Element
18. Event
19. EventTarget
20. HTMLCollection
21. MutationObserver
22. MutationRecord
23. NamedNodeMap
24. Node
25. NodeFilter
26. NodeIterator
27. NodeList
28. NonDocumentTypeChildNode
29. ParentNode
30. ProcessingInstruction
31. Selection
32. Range
33. Text
34. TextDecoder
35. TextEncoder
36. TimeRanges
37. TreeWalker
38. URL
39. Window
40. Worker
41. XMLDocument...

By purchasing this solution you'll be able to access the following files:

for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Web Development (HTML, XML, PHP, JavaScript, Adobe, Flash, etc.) Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats