Friday, November 22, 2019
Design Patterns - Behavioral, Creational, Structural Research Paper
Design Patterns - Behavioral, Creational, Structural - Research Paper Example There are several classifications of design patterns - this essay focus on three designs, including memento for behavioral patterns, singleton for creational patterns and lastly facade for structural patterns. Memento Pattern This is a software design pattern that has the capability of bringing back an object to its initial state. As a pattern, it allows the initial state of an object to be restored without interfering with the rules of encapsulation. This means that the arising object can be designed appropriately, though it can be restored to its original state. Therefore, memento pattern has the ability of restoring the internal state of an object without breaking the encapsulation rules. As a behavioral pattern, Memento indicates the manner through which communication between entities or classes is achieved (Schmidt, 1997). Basically, the design pattern is popular in applications with ââ¬Å"undoââ¬â¢ functionality. Memento pattern has two participants: the caretaker and the o riginator. The originator restores memento to its internal state while the caretaker guarantees memento safekeeping. According to Gamma et al. (1995), memento does not allow access to other objects other than originator. It has two interfaces, including narrow and wide interface. Caretakers only find the narrow interface and pass memento to other objects while the originator finds the wider interface through which it allows access to data that enabling restoration of the initial state. Benefits and drawbacks Memento pattern has chain of responsibilities that offers great flexibility especially when processing an application. In this case, it manages complex events by dividing the responsibilities into simpler elements that allows a set of classes to behave as a whole. However, the flexibility of this pattern is hard to develop, debug and test. This is because the chain becomes extremely complex. In addition, failure to plan for varied forwarding possibilities could result to message s that lack a handler, hence failing to attract any response. Singleton pattern Singleton is a creation design pattern that ensures only one object of a given class is created. It has only one class that is accessible by clients from identifiable access points. The single class must be extensible and the clients should easily use extended instances without alteration to their codes. Therefore, this pattern is particularly useful when a single object is needed to manage actions across a system. Singleton ensures efficiency when creating numerous identical objects and it uses a particular algorithm that requires a single point of control to interact with a resource that cannot be shared. Benefits and drawbacks The singleton pattern exerts control over the instantiation process and therefore this class has the flexibility to change the instantiation process. In addition, singleton pattern ensures that every object accesses the singleton object and preventing other objects from instanti ating their own copies. However, weaknesses associated with singleton pattern includes introduction a global state into the program. It allows uncontrolled access to the program hence being one of the most used patterns. In this regard, programs that are heavily used are difficult to test. This is because it is not possible to test it without testing other
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.