Sunday, October 22, 2017

Practical Software Architecture & Design with Sample Project Work

1. Fundamentals

1.1 Architecture

  • Is about system components, their responsibilities and their relationship; and to achieve system development, which is cost effective, replaceable, repeatable, reusable, secured, user friendly, maintainable, understandable, high performance and high availability.
  • It is about, conceptual and logical organization of system.Making a choice, so that NFR (Non Functional Requirements) are satisfied. 
  • NFR includes Quality requirements and Constraints.
  • Scope of the Architecture is Component

1.2 Design

Is about detailing of architecture to satisfy stakeholders requirements Scope of the Design is Objects and Classes


1.3 UML (Unified Modeling Language)

Universally accepted language for software design blueprints. It is a modeling language to document, visualize and model the software development artifacts.

1.4 Design patterns

Best possible (optimum) solution to the problem.


2. Object Oriented Concepts

2.1 Object Oriented (OO) programming languages

Examples are Java, C++, Smalltalk

2.2 Class

Is the blueprint/classification of the object.

2.3 Object

Instance of the class is called an Object.

2.4 Interface

Exposed by objects/components to external world to interact with it.

2.5 Encapsulation

Hide private data and exposed it using predefined interfaces with necessary validation or security.

2.6 Polymorphism

Dynamically decide the object (method) behavior at the runtime.


3. Selection of Architecture using Quality Attributes

Select Web Architecture based on the balance between Quality Attributes.



4. Types of Requirements

4.1 Functional Requirements

Is about Verb of the system
Should be same for different architectural options
      (For example, Calculate Net income)

4.2 Quality Attributes (QA) Refer : ISO25010

Is about Adjective of the systemDiffer as per architectural options (choices)
Usability, Performance, Security, Maintainability, Reliability, Portability and Availability

4.3 Constraints

Is about limitations,
Such as, System should support IE 10, budget < 10 Million Yen, developed in Java, deployed on on-premises
     Non Functional Requirements (NFR) = Quality Attributes + Constraints



5. System Development Life Cycle (SDLC)

  • Use various tools at the different level for the better productivity
  • SDLC can differ as per type of the Project



6. Practice Question Set 1

Q1. Write definition of Architecture & Design
Q2. Differences between Architecture & Design
Q3. Why Architecture is important
Q4. Create Architectural layers for a web system with related Requirements (all 3)
Q5. Propose Quality Attributes for the ATM machine
Q6. Explain Software Development Life Cycle (SDLC)
Q7. Difference between JDK, JRE and J2EE
Q8. List different Web servers and Application servers with some of their features
Q9. Explain about DMZ
Q10. Write a program in Java, which can read 2 numbers and display the result after addition



7. Modeling

  • is about designing of the software application before coding
  • is an essential part of the large complex software project
  • is like a blueprint
  • ensures functional and non-functional requirements
  • is the only way to visualize your design against the requirements before the coding and hence increases the chance of project success.
  • Allows to work at higher level of abstraction and also provides different views of the same system

Reference:
http://www.uml.org/what-is-uml.htm

8. Unified Modeling Language (UML)

UML is modeling language is used to document the design visually. It provides abstraction of the low level programming languages. Due to its abstract and visual nature, the UML facilitate design discussion among different types of stakeholders, such as technical and non-technical.
UML is a unification of many graphical modeling languages emerges from year 1980 to 1990. It is controlled by Object Management Group (OMG), which is open consortium of companies).

❖ OMG

OMG is open consortium of companies to build standards which supports interoperability of Object Oriented (OO) systems.
UML can be used as a sketch, blueprint or executable programming language. As per UML 2.0 there are 13 UML Diagram categories into 3 parts,

  • Structural Diagrams
    • Class Diagram (*)
  • Behavioral Diagrams
    • Use Case Diagram (*)
    • Activity Diagram (*)
    • State machine Diagram
  • Interaction Diagram
    • Sequence Diagram (*)
    • Communication Diagram
    • Timing Diagram
  • Interaction Overview
    • Object Diagram
    • Component Diagram (*)
    • Deployment Diagram (*)
    • Composite Structure Diagram
    • Package Diagram (*)

9. Calling of API [LAB]

  • Download HttpComponents -- https://hc.apache.org/downloads.cgi
       Java Client --[API]--> Remote Server

9.1 Calling API [LAB]

import java.io.IOException;
import java.util.Scanner;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;

public class TestAPIApp {

public static void main(String[] args) throws ClientProtocolException, IOException {
//https://hc.apache.org/downloads.cgi
HttpClient httpClient = HttpClientBuilder.create().build();
    HttpGet get = new HttpGet("http://finance.yahoo.com/d/quotes.csv?s=GOOG+AAPL+FB+TWTR&f=snl1ydr1qp2m5m6m7j1f6xj2s1va2ee7e8e9b4j4p5p6r5s7");
    HttpResponse response = httpClient.execute(get);
    HttpEntity entity = response.getEntity();
   
    if (entity != null) {    
        Scanner scanner = new Scanner(entity.getContent());
       
        while (scanner.hasNextLine()) {
        System.out.println(scanner.nextLine());
        }
       
        scanner.close();    
    }
}

}

OUTPUT

"GOOG","Alphabet Inc.",994.19,N/A,N/A,N/A,N/A,"+0.64%",71.01,+7.69%,54.03,688.85B,600574000,"NMS",692879000,N/A,211287,1424530,27.59,30.59,40.15,9.61,214.01,32.25B,6.89,4.62,1.62,2.07
"AAPL","Apple Inc.",156.815,1.620,2.520,"8/17/2017","8/10/2017","+0.522%",5.351,+3.533%,-0.893,809.99B,5031551000,"NMS",5165228000,N/A,3898191,27339900,8.808,9.010,11.000,3.800,25.615,70.21B,3.605,6.090,1.470,1.900 "FB","Facebook, Inc.",173.93,N/A,N/A,N/A,N/A,"+0.80%",15.86,+10.03%,3.54,505.13B,2341450000,"NMS",2904196000,N/A,3764486,15857000,4.47,5.34,6.51,1.70,22.92,18.08B,15.11,7.53,1.15,0.97
"TWTR","Twitter, Inc.",18.3799,N/A,N/A,N/A,N/A,"-0.3800%",1.1813,+6.8686%,0.9930,13.47B,645007000,"NYQ",732979000,N/A,3749118,14608000,-0.6270,0.3300,0.3500,0.1000,6.4520,142.67M,5.5080,2.8596,3.5200,3.6300



10. Practice Question Set 2

Q1. List 3 API with usage of each
Q2. What is modeling in software development
Q3. How UML can be used for modeling
Q4. List all UML diagrams and usage for each
Q5. Draw Use Case diagram for Pokémon go or any other game, and list use cases
Q6. Write use case details for above Q5 use cases
Q7. What is the difference between Use case and scenario, give one example
Q8. Draw deployment diagram for the typical web system of your choice
Q9. How Modeling and Quality Attributes are related
Q10. List software development methodologies



11. Analysis and Design





12. Practice Question Set 3

Q1. List different software development methodologies and which one do you prefer and why ?
Q2. What is the difference between Object analysis and Object Design
Q3. List steps to build a domain model
Q4. What is the main purpose of sequence diagram ?
Q5. What is the main purpose of deployment diagram ?
Q6. Draw class diagram and sequence diagram for ATM system
Q7. Define domain model for accounting system or system of your choice
Q8. List and describe symbols used to draw UML
Q9. Draw component diagram for ATM system
Q10. List tactics used for Modifiability Quality attribute



13. Component Diagram

  • It shows implementation view
  • It describes organization and dependencies among the software components It shows relationship among the components
  • Is used to model distributable physical unit, which includes components with well-defined interfacesPhysical unit

Physical unit
  • In case of software system : source code, Binary, Executable
  • In case of Human system : Documents, Vehicle

14. Quality Attribute & Tactic Diagram

15. Architecture Layers



16. Mechanisms


17. Practice Question Set 4

Q1. List Quality Attributes based on IS25010
Q2. List most important QAT (Quality Attributes) for the E-commerce system
Q3. List most important QAT (Quality Attributes) for the email system (such as Yahoo mail)
Q4. Describe Tradeoff analysis ?
Q5. Draw Component diagram for the online chatting system (LINE, Twitter)
Q6. Draw class diagram for the E-commerce system using MVC
Q7. Draw sequence diagram for login use case showing alternate flow (AF)
Q8. Draw deployment diagram for the E-commerce system (Show, Middleware and s/w components) 
Q9. Create eclipse project to develop dynamic web project
Q10. List Eclipse plug-ins for the eclipse embedded application server

Project: Online Banking System (OBS)


Create an Online Banking System (OBS), which will allow customer to do following actions securely,
  • View balance
  • Transfer money
  • Pay with net banking (Phase 2)
The web site should support desktop and smartphone.

The system should be release before December 2017 and support both English and Japanese User interface.


The average response time should be less than 4 seconds during the peak hours and system should be available 24 x 7, except planned maintenance window.


Your tasks


1. Follow SDLC and RUP methodology
2. Create detailed requirements
2.1 Functional Requirements (Using use case model)
2.2 Non-functional Requirements (QAT)
2.3 Constraints
3. Create Sequence diagrams for each use case
4. Create Domain Model
5. Create Component diagram
6. Create Deployment Diagram
7. Do Architectural Tradeoff Analysis (Tactics)
8. Create Infrastructure (using cloud?)
9. Do implementation (testing)
10. Validate the requirements and Document the results

Saturday, October 29, 2016

Project: E-commerce system Architecture, Design and Implementation

1.    Business Case

Develop online shopping web application, which is capable of secure online shopping and payment by credit card in addition to cash on delivery option (COD). The delivery of the goods should be completed within 2 working days.
The system will improve customer experience by allowing to shop online instead of visiting the stores, which finally results in satisfied customer and company (Sumedagawa Corporation) revenue growth.

Context Diagram:

2.    Use case model

(Interaction between actors and system.)

Figure 1: Use case model for E-commerce system


    Table 1: List of actors for the E-commerce system

Actor
Description
Customer
Customer interacts with the system to buy item, search item and do payment. No login is necessary to search an item.
Credit card Gateway
The gateway gets the input from the do payment use case to authorize the payment. For authorization purpose it connects to the credit card gateway.
Delivery Service
Deliver Service actor, delivers the item to the Customer as per instructions from the deliver item use case

2.1 List of use cases based on above use case model


ID
Use case title
Description
UC1
Do Sign-up
 New user sign-up
UC3
Do Login
Customer login
UC3
Search item
Search item based on the keyword
UC4
Buy item
Buy item after search
UC5
Do payment
Process order payment with external system
UC6
Deliver item
Deliver the item to the customer via delivery service

2.2 Use case details

2.2.1 Use case: Do Sign-up
Use case name
Do Sign-up
Use case ID

Description

Level

Primary actors

Supporting actors

Stakeholders

Pre-condition

Post-condition
Success end:

Failure end:

Minimum guarantee:

Main Flow (MF, success):












Extensions:








Sequence diagram (MF): Do Sign-up
To-do

2.2.2 Use case: Do login
Use case name
Do login
Use case ID

Description

Level

Primary actors

Supporting actors

Stakeholders

Pre-condition

Post-condition
Success end:

Failure end:

Minimum guarantee:

Main Flow (MF, success):












Extensions:








Sequence diagram (MF):  Do Login


Figure 2: Sequence diagram for Do Login scenario

2.2.3 Use case: Search item
Use case name
Search item
Use case ID

Description

Level

Primary actors

Supporting actors

Stakeholders

Pre-condition

Post-condition
Success end:

Failure end:

Minimum guarantee:

Main Flow (MF, success):












Extensions:








Sequence diagram (MF):
To-do

2.2.4 Use case: Buy item
Use case name
Buy Item
Use case ID
UC4
Description
Customer buys item by putting it into the shopping cart and checkout to do payment. Once the payment is confirmed the deliver service get notification about delivering the item to the billing address.
Level
High
Primary actors
Customer
Supporting actors
Credit card gateway,
Stakeholders
Customer, Delivery service, Credit card gateway
Pre-condition
Customer should be login
Post-condition
Success end: Customer successfully buys the item

Failure end: payment failure

Minimum guarantee: The transaction will atomic (full success or full rollback in case of failure)

Main Flow (MF, success):
1. Customer search item
2. System displays the item
3. Customer add the item to shopping cart
4. Customer checks out
5. System displays total payment information and credit card form
6. Customer enter credit card details and do payment
7. System gets authorization from credit card company
8. System displays payment and item confirmation details

Extensions:
7a. System gets un-authorization from the credit card company
1.  Customer can reenter card information and retry


Sequence diagram (MF):
To-do

2.2.5 Use case: Do payment
Use case name
Do payment
Use case ID

Description

Level

Primary actors

Supporting actors

Stakeholders

Pre-condition

Post-condition
Success end:

Failure end:

Minimum guarantee:

Main Flow (MF, success):












Extensions:








Sequence diagram (MF):
To-do

2.2.6 Use case: Deliver item
Use case name
Deliver item
Use case ID

Description

Level

Primary actors

Supporting actors

Stakeholders

Pre-condition

Post-condition
Success end:

Failure end:

Minimum guarantee:

Main Flow (MF, success):












Extensions:








Sequence diagram (MF):
To-do

2.3 Class Diagram:

Class
Responsibility



















3.    Requirements (primary requirements are drivers)

3.1 Functional requirements
ID
Requirement List
Primary?
FR1
Do Sign-up
Y
FR2
Do Login
Y
FR3
Search item
Y
FR4
Buy item
Y
FR5
Do payment
Y
FR6
Deliver item
Y

3.2    Quality attributes (NFR, driver)
ID
Quality Attribute
Outcome (Testable and Measureable)
QA1





















3.3         Quality attribute scenarios (driver)
ID
Quality Attribute
Scenario
Related UC
QAW1
Security
All transactions should be logged
UC2


All transactions should be secured with SSL
UC2

























     3.4   Constraints (NFR, driver)
ID
Type
Description
CN1
Business
System should be released before Dec. 2016
CN2
Technical
User accounts should be authenticated using internal customer db (non-cloud)
CN3
Technical
System must support IE browser, version 9 and above
CN4
Technical
Data source connection should be over JDBC protocol










     3.5    Architectural Concerns (driver)
ID
Description
ACN1
The system shall be programmed using Java and java based technologies
ACN2
Application logs shall be maintained using daily rotation








4. Architectural Documentation

4.1 Module Structure (dc: use reference architecture & deployment diagram)
(Static view)
TO-DO: DIAGRAM


Element
Responsibility



















4.2 Component & Connector Structure  (component diagram)
(Dynamic view)
TO-DO: DIAGRAM


Element
Responsibility




























4.3 Allocation View
(Relation of the system to non-software structures in the environment)
TO-DO: DIAGRAM


Element
Responsibility





















5. Implementation

Implementation is based on MVC (Model View Controller) design pattern. For class diagram please refer to section above.

Project Structure in Eclipse:


5.1 Source code:

[LoginManager.java]

package controller;

import java.sql.Connection;

import model.Login;
import model.dao.DBConnectionManger;
import model.dao.LoginDAO;

public class LoginManager {
      
       /**
        * Method to authenticate the user for the specified login information.
        * @param login login information
        * @return true if authentic user else return false
        */
       public boolean doAuthentication(Login login) {
             
              boolean result = false;
             
              try {
                     Connection connection = DBConnectionManger.getConnection();
                     LoginDAO loginDAO = new LoginDAO(connection);
             
                     result = loginDAO.doCheck(login);
                           
              } finally {
                     DBConnectionManger.closeConnection();
              }
             
              return result;
       }
}


[Login.java]

package model;

public class Login {

       private String userId;
       private String password;
      
       public String getUserId() {
              return userId;
       }
      
       public void setUserId(String userId) {
              this.userId = userId;
       }
      
       public String getPassword() {
              return password;
       }
      
       public void setPassword(String password) {
              this.password = password;
       }
}


[DBConnectionManger.java]

package model.dao;

import java.sql.Connection;
import java.sql.SQLException;

public class DBConnectionManger {

       private static Connection conn;
      
       /**
        * Method to return database connection based on the underlying database.
        * @return database connection
        */
       public static Connection getConnection() {
              //TODO: implement
              return conn;
       }
      
       /**
        * Method to close the DB connection
        */
       public static void closeConnection() {
                     try {
                            if (conn != null) {
                                   conn.close();
                            }
                     } catch (SQLException e) {
                            e.printStackTrace();
                     }
       }
}


[LoginDAO.java]

package model.dao;

import java.sql.Connection;
import model.Login;

public class LoginDAO {
             
       private static Connection conn;
      
       public LoginDAO(Connection connection) {
              conn = connection;
       }
      
       /**
        * Method to create login
        */
       public void create() {
             
       }
      
       /**
        * Check login details from the data source
        * @param login parameter with login details
        * @return true if authenticate else false
        */
       public boolean doCheck(Login login) {
              boolean result = false;
             
//TODO: implement      
              if (
                     login.getUserId().equalsIgnoreCase("Tokyo") &&
                     login.getPassword().equals("Osaka")
                     ) {
                     result = true;
              }

              return result;
       }

public Login doUpdate(Login existingLogin) {
              //TODO: implement
              return null;
       }
 }


[LoginManagerTest.java]

package controller;
import controller.LoginManager;
import junit.framework.TestCase;
import model.Login;

public class LoginManagerTest extends TestCase{
      
       public void testDoAuthentication() {
             
              LoginManager loginManager = new LoginManager();
             
              Login login = new Login();

              login.setUserId("tokyo");
              login.setPassword("Osaka");
             
              boolean result = loginManager.doAuthentication(login);
              assertEquals(true, result);
       }
}


[LoginDAOTest.java]

package model.dao;
import java.sql.Connection;

import junit.framework.TestCase;
import model.Login;
import model.dao.DBConnectionManger;
import model.dao.LoginDAO;

public class LoginDAOTest extends TestCase {

       Connection connection;
      
       @Override
       protected void setUp() throws Exception {
              connection = DBConnectionManger.getConnection();
              super.setUp();
       }
      
       public void testDoCheck() {

              LoginDAO loginDAO = new LoginDAO(connection);
      
              Login login = new Login();
              login.setUserId("tokyo");
              login.setPassword("Osaka");
             
              boolean result = loginDAO.doCheck(login);
             
              assertEquals(true, result);
       }
      
       public void testDoCheckFail() {

              LoginDAO loginDAO = new LoginDAO(connection);
      
              Login login = new Login();
              login.setUserId("tokyo");
              login.setPassword("osaka");
             
              boolean result = loginDAO.doCheck(login);
             
              assertEquals(false, result);
       }

       public void testCreate() {
              //TODO: implement
       }
     
       public void testUpdate() {
              //TODO: implement
       }
      
       @Override
       protected void tearDown() throws Exception {
              super.tearDown();
              connection.close();
       }