August 01, 2018

Object Oriented Analysis and Design Importance - Comprehensive


Text Book(s)
T1 Larman, C., Applying UML and Patterns, Pearson Education, 3rd Ed., 2005.
T2 Erich Gamma et al., Design Patterns: Elements of Reusable Object-Oriented Software, 1994

https://www.waseian.com/2018/08/object-oriented-analysis-and-design.htmlhttps://www.waseian.com/2018/08/object-oriented-analysis-and-design.html

Question 3)(i)
Online Mobile Recharge
Problem Statement:
   The event study 'Online Mobile Recharge' provides us the data about all the mobile service providers. This application offers us the complete info regarding any mobile service provider in terms of their policies, choices, profits, etc. Supposing, any Airtel buyer needs to have the info of all the schemes and services provided by the company, he/she can have the info and according to his suitability, he can recharge the mobile from the same application. The major benefit of this proposed system is to have the renewing facility of any service provider under the same roof.
End users
Service Provider:
  Service Provider is the one who is nothing but the mobile service provider like all the corporations who are giving the mobile connections come under this module. The functionality of this module is to mark the mobile renewing of their company based on the availability of balance in the admin account. Request derives from the user and it is going to be proved at the admin for the availability of balance and then the appeal is forwarded to the service provided to make the mobile recharge.
Third-party System Administrator:
The administrator is the one who observes all users and user dealings. Admin also observers all the Service Providers, all the user accounts, and amounts salaried by the user and amount salaried to Service providers. When the appeal given by the user admin checks the available balance in the user account then request is advanced to the Service Provider from where user request gets handled. Admin has the complete info related to the user and all the info related to the patterns and other info of dissimilar recharge coupons provided by the Service Providers. All the data is preserved at the Admin level. Admin is having the privileges to limit any user.
User:
  There are 2 categories in the user Module:
Registered User
Visitor
  Any person who wants to use the services of Online Mobile Recharge at any time from anywhere they should get listed in this application. After getting listed user can recharge the mobile at any time and from anywhere. Guest is the one who visits the Online Mobile Recharge application and has the complete data related to the Service Providers and can make the mobile recharge by entering the bank facts or by giving the credit card details.
Draw a Collaboration Diagram for the above case study clearly showing the Classes, Numbering of communications and relationships.
Answer)

IMPORTANT NOTE: In the question, only Collaboration Diagram is asked. Other diagrams are for reference.
Use-Case Diagram
Actors vs Use Cases:
User
•Register.
•Recharge.
•Select Payment Gateway.
•Select Service Provider.
•Make payment.

Third Party Administrator
•Forward User request to Service Provider.
•Track Complaints.

Third Party Server/ Database
•Authenticate the Registered users.
•Maintain the Log.

Service Provider
•Recharge the user requested either directly or through the third party system.
•Provide various plans to the user.

Online Mobile Recharge UML Use case Diagram:


Sequence Diagram
Sequence Diagram for a user to recharge his account through the third-party site:

Collaboration Diagram
Collaboration diagram for a user to recharge his account through the third-party site:

Class Diagram
Classes Identified:
  • User: Registered, Visitor
  • Third Party System Administrator
  • Third Party Server/ Database
  • Service Provider
  • Direct or Non- Third Party User (Direct access through Service Provider Site)

Activity Diagram
Activities:
  • User login and authentication for the Registered user.
  • Forward the request to service provider if logged in as an Administrator.
  • Enter service provider site for a direct user.
  • Enter recharge amount.
  • Select Payment Gateway.
  • Login and authenticate Bank Account.
  • Make payment.
  • Check for the recharge processed successfully or not.
Question3.(ii) 
Draw a UML Activity diagram clearly showing the interaction of Customer, Customer Browser, Google App, Google ACS Service, Identity provider for the Google Apps described below:
 Single Sign-On (SSO) for Google Apps
Purpose:
  An example of a UML activity diagram which describes Single Sign-On (SSO) to Google Apps for customers using some hosted Google application, such as Gmail.
Summary:

When a user tries to use some hosted Google app, such as Gmail, Google generates a (SAML) verification request and sends a redirect request back to the user's browser. Redirect points to the exact identity provider. SAML verification request contains the encrypted URL of the Google application that the user is trying to reach.
  Google acts as a service provider with services such as Gmail or Start Pages. Partner companies work as identifiers and control other passwords, passwords, and passwords used for identifying, authenticating and authorizing users for Google's Web applications. Each partner also provides Google with its SSO URL as well as a public key that Google will use to verify SAML
responses.

Answer: UML Activity diagram:
UML describe the structure, boundary, and behavior of the system as well as objects within it. It's not a programming language but there are tools which can be used to generate code in various languages.

Question4)(i) 
Factory Pattern: Explain through examples.
Answer )
Factory Method is to building objects as Template Method is to applying an algorithm. A super class identifies all standard and common behavior (using pure simulated "placeholders" for creation steps) and then delegates the creation details to sub classes that are delivered by the client.
  Factory Method creates a design more customizable and only a tiny more difficult. Other design patterns need new classes, while the Factory Method only requires a new process. Creating an object often requires difficult processes not appropriate to include within a composing object.
  The factory method design pattern handles these problems by defining a separate method for making the objects, which sub classes can then overrule to specify the derived type of product that will be formed.
Example:
The factory method allows an interface to create objects but the sub-classes can select which groups are immediate. Injection molding presses display this pattern. The manufacturers of plastic toys process plastic molding powder and inject plastic into the mold of desired shapes.
  The class of toy (car, action figure, etc.) is determined by the mold.

Question4)(ia)
How does the Factory Method Pattern fit in with other patterns/methods?
Answer ) 
  Factory classes are useful when you need a complicated process for building the object when the creation need a reliance that you do not want for the real class when you need to construct different objects etc.
  It is a good idea to use factory methods inside the object when:
  • Object's class doesn't know what exact sub-classes it has to create
  • Object's class is designed so that the objects it creates were specified by sub-classes
  • Object's class delegates its duties to auxiliary sub-classes and doesn't know what exact class will take these duties
  • The Factory Method allows these other patterns to defer instantiation to sub classes. One practices the Factory way to defer responsibility to sub class objects. 
Question4)(ib)
Factories increase cohesion. What is their rationale for saying so? 
Answer)
Cohesion means 'sticking together' and a factory is a method, an object, or anything else that is used to instantiate other objects. It helps to keep together both the functionality and the instruction that determines which objects should be built and/or managed under different circumstances.

Question4)(ic) 
Factories also help in testing. In what ways is this true?
Answer )
  • The using objects should act in exactly the similar way with any set of derivatives present. It should not test every possible combination, because it can test each piece individually. No matter how they are combined, the system will work in the same manner.
  • The advantage is that it can yield the same instance multiple times, or can return a subclass rather than an object of that exact type.
Question4.(ii)
Observer Pattern: Explain through examples
Answer)
  • Observer pattern (also called publishing-subscribed pattern) is a behavioral design pattern that defines multiple relationships between objects when an object changes its position, all dependent objects are notified and updates automatically.
  • Observer pattern is the basic standard in decoupling - separating objects which depend on each other.
Example:
  • The observer pattern is used in the model view controller (MVC) architectural pattern. In MVC observer pattern is used to decouple the model from the view. View symbolizes the Observer and the model is the Observable object.
  • Event management - For this scenario, the Observer patterns are widely used. Swing and DotNet are widely fulfilling the events mechanism.
Question4)(iia)
What is the intent of the Observer pattern? Under what circumstances should an Observer pattern not be used?
Answer)
The intent of the Observer Pattern:
  • Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
  • Is should be used when there is a change of a state in one object must be reflected in another object without keeping the objects tight coupled.
  • It is also used when the framework we are writing needs to be enhanced in the future with new observers with minimal changes.
  • When a change to one object requires the change of a variable number of other objects (not necessarily known at compile-time).
  • When an object should be able to talk to another object, but you don't want them essentially dependent on each other.
Question4)(ii)
One example of the Observer pattern from outside of software is a radio station: It broadcasts its signal; anyone who is interested can tune in and listen when they want to. Give another example from "real-life" with explanation?
Answer)
  • Split-wise group: If anyone adds or updates an entry in the group for any amount- all members of the group get a notification regarding the update done.
  • Facebook: If one follows a post, then it is added to the observer and another comment is received on the same post, send a notification to all other supervisors. It is the same as twitter or any other social media.
  • Cricket Display: The scoreboard display, displays the average score etc information as per the current status of the match. Whenever any total score changes, the display board gets refreshed. So, the display board is the observer here and Subject is the panel sending the current score status to the board.
Question5.(a)
Name three Design Patterns which uses the Singleton design pattern in their Implementation.
Answer)
Singleton design pattern is used in below three implementations.
  • Abstract Factory: In an abstract factory pattern, an interface is responsible for making a factory of related items without clearly specifying its classes.
  • Builder: Builder pattern builds a complex object using simple objects and using a step by step approach.
  • Prototype: This design involves applying a sample interface which speaks to create a replica of the current object. 
Question5.(b)
When singleton pattern usage is unnecessary?
Answer)
  • Most of the time it is not unnecessary.
  • When it's easier to permit an object resource as a reference to the objects that need it, rather than letting objects access the resource globally. 
  • Everything that can be done with a singleton can be done with a class variable or method.
  •  And if something has to be unique, it has to belong to the class and not to the objects.
  • Therefore, good or bad, singletons are conceptually wrong.
Question5.(c)
Compare the operation of Adapter and Bridge Design Patterns.
Answer)
Adapter Design Pattern
  • The adapter makes things work after they're designed.
  • The Adapter pattern is more about getting your existing code to work with a newer system or interface.
  • It is useful to work with two incompatible interfaces.
  • Example: A case of the rd reader which acts as an adapter between the memory card and a laptop. You plugin the memory card into card reader and card reader into the laptop so that memory card can be read via laptop
Bridge Design Pattern
  • Bridge makes them work before they are.
  • The Bridge pattern lets you have another implementations of an algorithm or system.
  • It decouples an abstraction from its implementation and both can differ individually.
  • Example: A circle can be drawn in various different colors using the identical abstract class method but diverse bridge implementer classes.
Question5.(d)
Why Decorator Design Pattern is better than Adapter Design Pattern while handling Interfaces?
Answer)
  • Adapter pattern alters interface, Decorator pattern doesn't alter interface, it just implements the unique object's interface, so that it can be passed to a method, which receives an original object.
  • Adapter delivers a different interface to its subject. Decorator delivers an enhanced interface.
  • An adapter is destined to change the interface of an existing object. Decorator enhances another object without changing its interface. A decorator is thus more transparent to the application than an adapter is. As a significance, Decorator supports recursive composition, which isn't possible with pure Adapters
Question5.(e) 
How does the Façade and Adapter Design Pattern make use of Interfaces?
Answer:
  • Facade describes a new interface, whereas Adapter reprocesses an old interface.
  • Facade design pattern neither translates interfaces nor adds new functionality, instead it just deliver simpler interfaces. So instead of client nonstop accessing single components of a system, it uses facade. Facade design pattern agrees client interact with the difficult system with a much simpler interface and less work
  • The facade will then call individual components.