• Save
Ajs 2 b
Upcoming SlideShare
Loading in...5
×
 

Ajs 2 b

on

  • 584 views

 

Statistics

Views

Total Views
584
Views on SlideShare
549
Embed Views
35

Actions

Likes
0
Downloads
0
Comments
0

1 Embed 35

http://niitcourseslides.blogspot.in 35

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Ajs 2 b Ajs 2 b Presentation Transcript

  • More on Design PatternsPre-assessment Questions 2. Which UML diagram depicts the sequential invocation of methods of a system? a) Sequence b) Collaboration c) Package d) Use Case ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 1 of 35
  • More on Design PatternsPre-assessment Questions 2. Which option identifies the scope of a system in a Use Case diagram and is represented by a solid rectangle? a) Use Case b) Message c) Actor d) State boundary ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 2 of 35
  • More on Design PatternsPre-assessment Questions 2. Consider the statements: Statement A: Extent relationship indicates that an existing use case is extended by additional behavior to obtain another use case. Statement B: Include relationship indicates that the functions of one use case are included in the functions of the other. Identify the correct option. a) Statement A is true and statement B is false b) Statement A is false and statement B is true c) Both, statements A and B, are true d) Both, statements A and B, are false ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 3 of 35
  • More on Design PatternsPre-assessment Questions 2. Consider the statements: Statement A: Component diagram represents the grouping of related classes, interfaces, and methods of a given system. Statement B: Component diagram elements represent the various components of business entities of a given system. Identify the correct option. a) Statement A is true and statement B is false b) Statement A is false and statement B is true c) Both, statements A and B, are true d) Both, statements A and B, are false ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 4 of 35
  • More on Design PatternsPre-assessment Questions 2. Which element of GoF’s design pattern emphasizes on relationships, responsibilities, and collaborations among the constituents of a pattern? a) Pattern name b) Solution c) Problem d) Consequences ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 5 of 35
  • More on Design PatternsSolutions to Pre-assessment Questions 1. a. Sequence 2. d. State boundary 3. c. Both, statements A and B, are true 4. b. Statement A is false and statement B is true 5. b. Solution ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 6 of 35
  • More on Design PatternsObjectives In this lesson you will learn to: • Use Structural Design Patterns • Use Behavioral Design Patterns ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 7 of 35
  • More on Design PatternsStructural Design Patterns • Structural design patterns • Represent the composition of classes and objects. • Defines how classes inherit each other. • The class-creation pattern uses inheritance in order to provide more functional program interfaces. • The object-creation pattern defines how objects can be composed to provide new functionality using object composition. • The various structural design patterns are Adaptor, Bridge, Composite, Decorator, Façade, Flyweight, and Proxy. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 8 of 35
  • More on Design PatternsStructural Design Patterns (Contd.) • Adapter Pattern • The Adapter design pattern • Converts the interface of a class into an interface that is required by the client. • The advantages of using Adapter design pattern are: • Enabling two or more incompatible objects to interact with each other. • Making an existing functionality reusable. • The participants of Adapter design pattern are: • adapterTest : Implements the methods of MouseAdapter class. • MouseListener: Receives the mouse events generated. • MouseAdapter: Provides blank implementation of the methods defined in the MouseListener abstract class. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 9 of 35
  • More on Design PatternsStructural Design Patterns (Contd.) • Class diagram of the Adapter design pattern ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 10 of 35
  • More on Design PatternsStructural Design Patterns (Contd.) • Bridge Pattern • The Bridge design pattern • Separates an interface and its implementation. This enables both the interface and its interface to change without affecting each other. • Uses encapsulation, aggregation, and inheritance to divide responsibilities into various classes. • The advantages of using Bridge design pattern are: • Separates the implementation details from interface. • Hides implementation details from the client. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 11 of 35
  • More on Design PatternsStructural Design Patterns (Contd.) • The participants of Bridge design pattern are: • ClientApp: Invokes the methods of ConcreteImplementor1 and ConcreteImplementor2 class. • Abstraction: Defines the methods that are implemented by ConcreteImplementor1 and ConcreteImplementor2 classes. • RefinedAbstraction: Extends the methods defined by class, Abstraction. • Implementor: Extends the methods of the Abstraction class to the implementation classes, ConcreteImplementor1 and ConcreteImplementor2. • ConcreteImplementor1: Implements the methods defined in the abstract class, Implementor. • ConcreteImplementor2: Implements the methods defined in the abstract class, Implementor. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 12 of 35
  • More on Design PatternsStructural Design Patterns (Contd.) • Class diagram of the Bridge design pattern ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 13 of 35
  • More on Design PatternsStructural Design Patterns (Contd.) • Composite Pattern • The Composite design pattern • Composes objects into tree structures. • Enables a client to identically treat both the single component and collection of components. • The advantages of Composite design pattern are: • Adds new components. • Describes the hierarchies of a class, which consists of primitive and complex objects. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 14 of 35
  • More on Design PatternsStructural Design Patterns (Contd.) • The participants of Composite design pattern are: • ClientClass: Invokes methods of an object through Component interface. • Component: Declares interface for accessing and managing its child components. • Leaf: Defines an object in composition, which has no children. • Composite: Defines behavior for parent components and stores child components. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 15 of 35
  • More on Design PatternsStructural Design Patterns (Contd.) • Class diagram of the Composite design pattern ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 16 of 35
  • More on Design PatternsStructural Design Patterns (Contd.) • Decorator Pattern • The Decorator design pattern • Enables you to extend the functionality of a particular object of a class and dynamically provide additional responsibilities to it. • Uses composition instead of inheritance in order to extend the functionality, the Decorator design pattern. • The advantages of using Decorator design pattern are: • It makes it easy to code a behavior, by enabling you to create functionality classes. • It is more flexible as compared to static inheritance. • It improves the extensibility of an object as you code new classes to make a change in functionality. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 17 of 35
  • More on Design PatternsStructural Design Patterns (Contd.) • The participants of Decorator design pattern are: • Component: Describes the functionality that the client requires. • ConcreteComponent: Implements the functionality described in the abstract class, Component and represents the object to which you can add additional functionalities. • Decorator: Enables ConcreteDecorator1 and ConcreteDecorator2 to implement the functionality of the abstract class, Component. • ConcreteDecorator1: Implements the functionality of the abstract class, Component through the abstract class, Decorator. • ConcreteDecorator2: Implements the functionality of the abstract class, Component through the abstract class, Decorator. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 18 of 35
  • More on Design PatternsStructural Design Patterns (Contd.)• Class diagram of the Decorator design pattern ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 19 of 35
  • More on Design PatternsStructural Design Patterns (Contd.) • Facade Pattern • The Façade design pattern • Provides a unified interface to a collection of interfaces in a subsystem. • The advantages of using Façade design pattern are: • Simplifies the interfacing that makes it difficult to use a large amount of coupling. • Protects the client from the complex subsystem components. • The Façade design pattern has two participants: • Façade: Is also a participant of a system that intercepts client requests and dispatches the request to the subsystem to service the client request. • SubSystemN: Defines an application, which uses a façade to interact with the client. There can be multiple subsystems in an application, such as SubSystem1, SubSystem2, …, SubSystemN. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 20 of 35
  • More on Design PatternsStructural Design Patterns (Contd.) • Class diagram of the Façade design pattern ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 21 of 35
  • More on Design PatternsStructural Design Patterns (Contd.) • Flyweight Pattern • The Flyweight design pattern is used to efficiently share information between a large numbers of objects. • Several objects may exist in a system, each using some information and thereby consuming a large amount of memory. • If all the objects share some static information, you can remove that information from each object and place in one object. • All other objects can refer to this object, thus reducing the memory requirement of the system. • The object, which contains the common information that is referenced by other objects, is known as the flyweight object. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 22 of 35
  • More on Design PatternsStructural Design Patterns (Contd.) • The advantages of using Flyweight design pattern are: • Enabling large amount objects to share information. • Making optimum use of memory. • The participants of Flyweight design pattern are: • FlyweightFactory: Creates the flyweight objects. • Flyweight: Declares an interface to enable the flyweights to interact with the abstract state. • ClientApp: Invokes the methods of FlyweightFactory class. • ConcreteFlyweight: Implements the functionality of the abstract class, Flyweight. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 23 of 35
  • More on Design PatternsStructural Design Patterns (Contd.)• Class diagram of the Flyweight design pattern ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 24 of 35
  • More on Design PatternsStructural Design Patterns (Contd.) • Proxy Pattern • The Proxy design pattern enables you to provide a stand-in object in place of another object. • The stand-in object receives the requests that are meant for the original object and delegates the requests to the original object. • The examples of proxy are remote and virtual. • A remote proxy object provides a local representation of an object that runs in a different address space. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 25 of 35
  • More on Design PatternsStructural Design Patterns (Contd.) • The advantages of using Proxy design pattern are: • A remote proxy provides location transparency to the client of object. • A virtual proxy provides memory optimization be creating objects when required. • The participants of Proxy design pattern are: • ClientProgram: Invokes the methods on a remote object. • InterfaceMatter: Declares the methods, which are implemented by the Matter class. • Matter: An object that provides services to its clients. • Proxy: An object that intercepts the requests and delegates them to the original object. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 26 of 35
  • More on Design PatternsStructural Design Patterns (Contd.)• Class diagram of the Proxy design pattern ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 27 of 35
  • More on Design PatternsIdentifying Structural Design Patterns • Problem Statement • BlueMoon Inc. provides software consultancy services. The company foresees a high demand for the retail automation software. As a result, BlueMoon Inc. decides to develop Retailer Automation Solution (RAS), which provides the functions to update the inventory, automate the sales record, and reduce the transaction-processing time. RAS needs to be developed in a way that it can be modified according to the specific requirements of each retailer. For this reason, BlueMoon Inc. ensures that RAS is extensible and adaptable, which enables BlueMoon Inc. to reuse the components of the RAS to create customized solutions for different retailers. John, the software consultant at BlueMoon Inc. decides to model the structural diagram and identify the various structural design patterns, which will enable him to reuse the existing components. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 28 of 35
  • More on Design PatternsIdentifying Structural Design Patterns (Contd.) • Solution • To solve the preceding problem, perform the following tasks: • Draw the structural diagram of the application. • Identify the Decorator design pattern. • Identify the Proxy design pattern. • Identify the Bridge design pattern. • Identify the Facade design pattern. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 29 of 35
  • More on Design PatternsBehavioral Design Patterns • The Behavioral design pattern • Defines the state, behavior, and communication among the objects. • Various Behavioral design patterns are Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, and Visitor. • Chain of Responsibility Pattern • Chain of Responsibility design pattern • Decouples the sender and receiver of a request by introducing a number of objects between them. • The advantages of using Chain of Responsibility design pattern are: • Enabling a group of classes to act as a single class. • Providing flexibility while dividing responsibilities among the objects. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 30 of 35
  • More on Design PatternsBehavioral Design Patterns (Contd.)• Class diagram of the Chain of Responsibility design pattern ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 31 of 35
  • More on Design PatternsBehavioral Design Patterns (Contd.) • Command Pattern • The Command design pattern • Encapsulates a request as an object and enables the queuing and logging of requests. • Supports undo operations. • The advantages of using Command design pattern are: • Enables you to execute the commands whenever the resources are available. • Enables you to add new commands, as the existing classes do not change. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 32 of 35
  • More on Design PatternsBehavioral Design Patterns (Contd.)• Class diagram of the Command design pattern ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 33 of 35
  • More on Design PatternsSummary • Structural design patterns that describe the composition of the classes and objects. This design pattern introduces a level of indirection between a client class and the class that the client wants to use. The various structural design patterns are: • Adapter: Enables classes of different interfaces work together in a single program. • Bridge: Separates an interface from its implementation so that either can be changed without affecting each other. • Composite: Enables a client to identically treat both the single component and collection of components. • Decorator: Enables you to extend the functionality of a particular object and dynamically provide additional responsibilities to it. • Façade: provides a unified interface to a collection of interfaces in a subsystem. • Flyweight: Enable you to share information among a number of objects. • Proxy: Enables you to provide a stand-in object in place of another object. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 34 of 35
  • More on Design PatternsSummary(Contd.) • Behavioral design patterns that describe the behavior of an object. The various Behavioral design patterns are Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, and Visitor. • Chain of Responsibility: Defines a number of classes can handle a request without knowing the capabilities of other classes. • Command: Dispatches a request to a specific application. ©NIIT Architecting J2EE Solutions Lesson 2B / Slide 35 of 35