Couple of Days back i started reading Design Patterns Java™ Workbook By Steven John Metsker.
Nice book written by Steven John Metsker.
I wanted to share few quotations found the book from the next 2 chapters (19-20).
1) Sometimes, you want to create an object that existed previously. This occurs when you want to let a user undo operations, revert to an earlier version of work, or resume work that he or she previously suspended. The intent of the MEMENTO pattern is to provide storage and restoration of an object's state.
2) Memento Durability
A memento is a tiny repository that saves an object's state. You can create a memento by using another object, a string, or a file. The anticipated duration between the storage and the reconstruction of an object has an effect on the strategy that you can use in designing a memento. The time that elapses can be moments, hours, days, or years.
3) Wikipedia Says:
Provides an ability to restore an object to its previous state(undo via rollback).Memento Pattern is used by two objects.The originator and a caretaker.The originator is some object that has an internal state.Caretaker is going to perform some action to the originator,but wants to be able to undo the change.
4) Persisting Mementos across Sessions
A session occurs when a user runs a program, conducts transactions in the program, and exits.Suppose that your users want to be able to save a simulation in one session and restore it in another session. This ability is a matter normally referred to as persistent storage. Persistent storage fulfills the intent of the MEMENTO pattern and is a natural extension to the undo functionality you have already implemented.
5) Using Strings as Mementos
Object serialization provides a simple means for a memento to persist across multiple sessions that occur, say, on a given day. If, on the other hand, your user wants to revive a simulation after a six-month sabbatical, he or she may find that various classes in the simulation package have evolved to new versions. The java.io package provides some support for deserializing an object when its class has changed since the serialization was written, but proper handling of object serialization across class versions is, in practice, problematic. To avoid this problem, you can "serialize" your object to text.
6) The MEMENTO pattern lets you capture an object's state so you can restore the object later.The means of storage may depend on whether you need to be able to restore an object after a few clicks and keystrokes or after days or years. The most common reason for saving and restoring objects during an application session is the support of undo operations. In such a case, you can store an object's state in another object, possibly a clone. To let an object persist across sessions, you can save the memento either through object serialization or as text that you will parse to restore the object.
7) Operations, Methods, and Algorithms
It is useful to distinguish operation from method and to then discuss these concepts' relations to algorithm. Fortunately, the UML defines the difference between an operation and method (Booch, Rumbaugh, and Jacobson 1999, p. 128).
• An operation is a specification of a service that can be requested from an instance of a class.
• A method is an implementation of an operation.
8) A signature specifies which method is invoked when a client makes a call. So how is signature different from operation? After all, both terms refer to the specification of a service.The terms differ mainly in the context in which they are typically used. The term operation applies when discussing the idea that methods in different classes may have the same interface. The term signature applies when discussing the rules that govern how Java matches a method call to a method in the receiving object.
In Java, a method declaration includes a header and a body. A method's body is the series of instructions that can be called into action by invoking the method's signature.
9) Although it is common to intermingle the meanings of operation, method, signature, and algorithm, preserving distinctions among these terms helps to describe important concepts.
An operation is, like a signature, a specification of a service. The word operation applies when talking about the idea that many methods may have the same interface. The word signature applies when discussing method lookup rules. A method definition in-cludes its signature—its name and parameter list—along with modifiers, return type, a throws clause,and the method's body. A method has a signature and implements an operation.
An algorithm is a procedure that accepts inputs and produces outputs. Methods accept inputs,produce outputs, and contain a procedural method body, so it is common to refer to a method as an algorithm. However, an algorithm's procedure may involve many operations and methods, or it may exist as part of another method. The word algorithm best applies when you are discussing a procedure that produces a result.
Many design patterns involve distributing an operation across several classes. You can also say that these patterns rely on polymorphism, the principle that method selection depends on the class of the object that receives a method call. The decision of which method executes depends on many rules and various aspects of method headers. In particular, it is important to understand that the static modifier means that the decision of which method to execute depends on the receiver's declared type, not the class of the object.
Methods execute until they return, unless they produce an exception. The potential for some exceptions is so commonplace that methods need not declare them. Other, checked exceptions must appear in a method's throws clause. The decision of whether an exception should be checked or unchecked is a matter of judgment.
Monday, 12 January 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment