Process Models


Revisit the concepts of Process Models

  • Waterfall model

    • Risk of building wrong system due to no user feedback, Operational quality portion of product in the end
    • Only work best when there is a complete and frozen specification document
  • V-model

    • Basically waterfall model, but represented as a V-shape to emphasize verification and validation using different type of testing
    • Still have the same risk of Waterfall model.
  • Evolutionary Model

    • requirements evolve
  • Build and Fix model

    • no planning
  • Rapid prototyping model

    • More customer involvement than Waterfall model and V model
  • Incremental model

    • still fixed requirement, but each release more functionality

What is the biggest drawback of the waterfall model?

Risk of building wrong system/delivering incorrect product due to not enough feedback

How can you address the main risk of the waterfall model?

Obtain more frequent feedback from customer/users; e.g., building a prototype up front, or using an iterative model

What is the main idea behind the V process?

Linking unit, integration, and system test stages with, respectively, unit design, system design, and system specification.

What is the main difference between the waterfall model and the V-model?

V-model is basically the waterfall model emphasise Verification and Validation using different type of testing

V-model is like waterfall, but it adds more detailed stages for the V&V part, including unit, integration, and system testing (and acceptance testing); each of these test stages is fed with specification information from, respectively, unit, design, and requirements development stages.

What problem does early prototyping address?

Reducing the risk of building wrong system because more customer involvement

What lifecycle model is used in agile development?

Evolutionary model

When is the waterfall model applicable?

When the customer requirements are fully clear and frozen (no uncertainties)

Draw the V-model

img

Draw the Evolutionary model

img

Requirement Engineering


Revisit functional requirement (F) vs non-functional (quality) requirement (N)

  • Functional Requirement: what functions the system should perform
    • No technical mentioned
    • “how the system should perform”
    • Phrased as actions
  • Non-functional Requirement: quality requirements state with what quality it should perform
    • More like technical requirement, e.g. performance, implementation, safety concerns
    • Has nothing to do with “how the system should perform”
    • Phrased as constraint or negative assertion

For each requirement below, indicate whether it is a functional requirement (F) or a non-functional requirement (N):

The system should be designed so it can be later extended to handle a frequent- flyer plan.

N.
This is clearly a implementation concern.

The system will allow the user to view the layout of seats in an aircraft.

F.
Only involves how the system should perform.

The system must be available at all times. Only 2 minutes of downtime per week is to be permitted.

N.
This is a performance concern.

A given seat can be assigned to at most one person at any given time.

F.
Only involves how the system should perform.

The online shopping system shall allow the shopper who initiated an order or a senior manager to cancel the order anytime before shipment.

F.
Only involves how the system should perform.

The system shall prevent any unauthorized person, that is, one other than the shopper who initiated an order or a senior manager, from canceling the order.

N.
This is a safety implementation concern.

After requesting the cancellation of an order by a user, the system shall provide the user with an acknowledgment whether the cancellation was successful or not.

F.
Only involves how the system should perform.

The acknowledgment shall be displayed to the user no later then 15 seconds after the user has requested the cancellation.

N.
This is clearly a implementation concern.

Only authorized persons should be able to access customer data.

N.
This is clearly a implementation concern.

The system should allow a customer to search products by type and brand.

F.
Only involves how the system should perform.

The throughput of the system should double when doubling the number of servers.

N.
This is clearly a implementation concern.

Only 2 minutes of downtime per week is to be permitted.

N.
This is clearly a implementation concern.

The system should provide a two-factor authorization function and require every user to use it.

N.
This is clearly a implementation concern.


Revisit “Necessary properties of requirements” and “Desirable properties of requirements”

Necessary properties of requirements

  • Unambiguous (the meaning should be clear)
  • Consistent (one requirement must not contradict another)
  • Complete E.g.: “The process is terminated if the wrong PIN has been entered more than a certain number of times.” (What is that number?)
  • Verifiable (possible to test: a requirement that cannot be tested is not a requirement)

Desirable properties of requirements

  • Free of implementation bias (Only What, Not How; Only Specification, Not Solution)
    • It should be realizable with reasonable effort

For each of the following statements below, indicate whether it would be appropriate as a requirement or not. If not, provide an explanation and suggest an improvement.

The automatic teller machine will have fast response time.

Inappropriate. This performance requirement is not testable. It could be corrected by specifying minimum response time for specific requests or for all user requests.

The name list will be sorted in alphabetical order using quicksort before printing.

Inappropriate. It has to be Free of implementation bias. Quicksort algorithm term should be removed.

The system will be easy to use.

Inappropriate. This requirement is not Verifiable nor testable. It could be corrected by specifying efficiency and effectiveness targets for performing specific tasks by users with specific training.

The system should allow a user to display previous orders placed from the user’s account, which are stored on the hard disk.

Inappropriate. It has to be Free of implementation bias. The solution “stored on the hard disk” us should be removed.

The system must be highly available. Only 2 minutes of downtime per week is to be permitted.

Appropriate. The requirement is clear, consistent (highly available | 2 minutes downtime per week), Complete (2 minutes instead of few minutes), Verifiable (possible to test).

The system will have fast response time.

Not appropriate. It cannot be verified. Target metric such as worst response time or average response time needed.

The system should allow a user to display previous orders placed from the user’s account within the last 6 months.

Appropriate. It is complete and verifiable.

The system will allow the user to sort the entries in the previous-order list by date, product name, or price, using bubble sort.

Not appropriate. Restricting to bubble sort represents implementation bias.

Testing


Topic Summary:

Purpose of Testing: reveal the presence of errors NOT their absence

Unit Testing: Objective: Find differences between specified Unit; localize bugs

Integration Test: Objective: To expose problems arising from the combination

System Test: Target System Design

Acceptance Test: Target User requirements; ensure that end users are satisfied

Regression Test: Entire test when system is modified

Black-box Testing: Deriving test from requirements, interfaces

  • Black-box Coverage Examples: Input partition, Input property combination

White-box Testing: Deriving tests to cover design & implementation

  • White-box Coverage Examples: Input partition, Structural coverage (coverage of design and code)

Failure: the external behavior does not conform to system spec

Error: a state of the system which, in the absence of any corrective action, could lead to a failure.

Fault: An adjudged cause of an error.

  • Fault causes Error, Error cuases Failure

Code coverage:

  • Statement coverage: all nodes

    • need to make sure all the statements (i.e. lines of code) are executed at least once in statement coverage
  • Branch coverage: all edges

    • All possible values of the constituents of compound conditions are exercised at least once.
  • Path coverage: all execution paths

    • cover all feasible paths

Which statement is correct? Mark both if both correct.

  • Testing can show the absence of bugs.

Not Correct. It should be presence, no absence.

  • Testing can show the presence of bugs.

Correct.

  • Testing improves software quality.

Correct.

Can testing ensure program correctness? Explain why it can or cannot.

It cannot. For non-trivial programs, the space of inputs is too big to check completely in practice.

Give an example of a black-box coverage metric.

Coverage of requirements (or coverage of input partitions, or input property combination)

What is the difference between acceptance and system testing?

Acceptance testing targets the user/customer requirements;

System testing is informed also by the system design

What is the key benefit of unit testing as compared to system testing?

Unit testing find differences between specified Unit, so the bugs are localized

Unit testing only involve one unit while system testing involve multiple units; easier to find presence of bugs

What is the difference between black-box and white box testing?

Black-box Testing: Deriving test from requirements, interfaces

White-box Testing: Deriving tests to cover design & implementation

Black-box tests are designed wrt. requirements and interfaces; white-box tests take design and implementation into account.

What is structural coverage?

structural coverage is the coverage of design and code (white-box)

Scalability testing would be part of which type of testing? Unit or system?

System testing.

Failing a unit test indicates the following (select all that applies)?

  • System error [ ]
  • Unit failure [ ]
  • System fault [ ]
  • Unit error [ ]
  • Unit fault [ ]
  • System failure [ ]

unit test fail = unit fault casuing unit error, unit error causing unit failure

then unit failure causing system fault and error, but not necessary

System error [X]
Unit failure [X]
System fault [X]
Unit error [X]
Unit fault [X]
System failure [ ]

Consider the following sample program, draw its control-flow graph and give a test vector (Boolean assignments to A,B,C; and a natural number to N) set for statement coverage, branch coverage, and path coverage (for simplicity, consider one iteration at maximum). An example of a test vector is A, not B, ?, ? (the question mark indicates “don’t care” for the respective input). The test vector sets should be minimal (i.e., if any of the vectors is removed from a set , the respective coverage is not achieved).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Input: A,B,C,N
If A then
If B then
S1
Else
S2
End if;
S3
Else
If C then
S4
End if;
S5
For i:=0;i++;i<N do
S6
End for;
End if

img

Consider the following sample program, draw its control-flow graph and give a test vector (Boolean assignments to A,B; and a natural number to N) set for statement coverage, branch coverage, and path coverage (consider up to one unrolling of the loop for path coverage). An example of a test vector is A, ?, ? (the question mark indicates “don’t care” for the respective input). The test vector sets should be minimal (i.e., if any of the vectors is removed from a set , the respective coverage is not achieved).

1
2
3
4
5
6
7
8
9
10
11
12
Input: A,B,N
If A then
S1
Else
S2
For i:=0;i++;i<N do
S3
End for;
If B then
S4
End if;
End

img

Consider the following sample program, draw its control-flow graph and give a test vector (Boolean assignments to A,B,C,D) set for statement coverage, branch coverage, and path coverage (consider up to one unrolling of the loop for path coverage; for simplicity, assume that S5 sets C to false). An example of a test vector is A, not B, ?, ? (the question mark indicates “don’t care” for the respective input). The test vector sets should be minimal (i.e., if any of the vectors is removed from a set , the respective coverage is not achieved).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Input: A,B,C,D
If A then
If B then
S1
Else
S2
End if;
S3
Else
S4
While C do
S5
End while;
If D then
S6
End if;
End

img

Modularity


Revisit Module, Interface, Implementations

Module

  • Module is a unit of decomposition with interface and implementation

Interface

  • Interface is a contract between modules and its environment
    • Provided inferface = called by the environment
    • Required inferface = called by the module
img

Implementation

  • Implementation is the hidden details of how things done.
    • Algorithms, data structures, mechanisms

About operation specs

  • Syntactic = how to invoke it (module name, parameters, parameter types, return types)
  • Semantic = what it does (what the module / function solve, performance characteristics, preconditions, error codes)

What is a module?

A Module is Unit of system decomposition with a clear purpose and an interface

One important role of modules is to allow understanding a system piece by piece. Name two other roles modules can play in software development?

  • Dividing work among developers
  • Unit of reuse (use a module several times in one system or across several systems)
  • Unit of evolution (encapsulate change)
  • Unit of compilation (in a programming language)

What is an interface?

An interface is a contract between module and environment

Imagine that you are implementing a customer record search module. Select which of the following information would be appropriate to include in the interface description of the module.

Operation signatures [ ]
Return codes of operations [ ]
Data structures used in the implementation [ ]
List of interfaces of other modules used in the implementation [ ]
Search algorithms used in the implementation [ ]
Latency of the search operation [ ]
Preconditions on arguments [ ]
Postconditions [ ]

Operation signatures [X]
Return codes of operations [X]
Data structures used in the implementation [ ]
List of interfaces of other modules used in the implementation [X]
Search algorithms used in the implementation [ ]
Latency of the search operation [X]
Preconditions on arguments [X]
Postconditions [X]

Consider an operation for which a signature with the pre-and postconditions over the states manipulated by the operation is specified. Please classify this type of specification.

“syntactic only” [ ]
“semantic only” [ ]
“syntactic and semantic” [X]

What is the main problem with using global variables?

They introduce side effects / They introduce hidden dependency / They make hard-to-understand and hard-to-test code / Namespace pollution / Potential memory allocation issues / Potential concurrency issues / Potential security issues / …

Consider a Java implementation of a module below. It consists of two interfaces and a class containing the module implementation. Which interface, A or B, in the Java code fragment below is a required interface of the module?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public interface A 
{...}
public interface B
{...}
public class C implements A // Called by the environment
{
private B b;
// Called by the module

public C (B b)
{ this.b=b; }

public void do()
{ ...
b.do();
... }
}

Provided inferface = called by the environment

Required inferface = called by the module

B is the required interface of the module

A is the provided interface of the module

Consider the following three specs of an operation:

  1. Spec A: The operation Status open(FileHandle f) takes a parameter of type FileHandle and returns a value of type Status.
  2. Spec B: The operation Status open(FileHandle f) takes a parameter of type FileHandle and returns a value of type Status. Status equal 1 indicates success, in which case the file handle is in the state “open”.
  3. Spec C: The operation Status open(FileHandle f) takes a parameter of type FileHandle and returns a value of type Status. A call to open(f) has to return no late than 1ms.

Please classify each of the three specs as either “syntactic only” or “syntactic and semantic”.

  • Spec A is …

Syntactic only. Because it only has the signature, parameter, and the return type. No semantic.

  • Spec B is …

Syntactic and semantic exists. Exit code is explained. It also explained what the operation do.

  • Spec C is …

Syntactic and semantic exists. Performance characteristics are mentioned.

Consider a Java implementation of a module below. It consists of two Java interfaces and a class containing the module implementation. Which Java interface, A, B, or C in the Java code fragment below is a provided interface of the module?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public interface A { ... }
public interface B { ... }
public interface C { ... }
public class D implements C {
private B b;
private B c;

public C(B b, C c) {
this.b = b;
this.c = c;
}

public void do() { ...
b.do();...
}
}

Provided inferface = called by the environment

Required inferface = called by the module

C is the provided interface of the module

B is the requried interface of the module

What type of requirements tend to result in cross-cutting?

Cross-cutting happen when 1 requirement impacting a lot of modules.

This is usually happened in Non-functional (quality) requirements.

Why? compare to the functional requirements, where you can meet a new requirement by modifying the specific corresponding module, or create a new one for it, e.g., EmailVerification module. Quality requirements are more like global requirements, like all APIs needs to be authenticated or the responding delay must be within 5 seconds. It’s hard to have a module like AuthenticateAllApi or FastRespond, and it is hard to achieve them without modifying many modules or using some crafty mechanisms.

Consider the following interface specification and judge if it contains syntactic and semantic.

1
2
Signature: void print(Buffer) 
Maximum memory use: 2 Mbyte

The specification is syntactic and semantic.

Syntactic: return type (void), module name (print), parameter (Buffer)

Semantic: Performance charactistics (maximum memory use)

The interface construct in Java captures the syntax of an interface. Give two examples of semantic aspects not covered by the Java interface construct. For each of them, provide an idea of how it could be captured.

Example 1: Behvior

Way to capture: can be captured using assertions (pre and post conditions), state machines, tests and/or documentation

Example 2: Performance

Way to capture: can be captured through documentation, e.g., response time

Example 3: Reliability

Way to capture: can be captured in documentation

ShoppingCart is a Java class implementing a shopping cart component. One of its fields has the type TaxCalculatorI, which is a Java interface. Which of these statements is correct?

(i) TaxCalculatorI is a provided interface of ShoppingCart.

(ii) TaxCalculatorI is a required interface of ShoppingCart.

Provided inferface = called by the environment

Required inferface = called by the module

Therefore TaxCalculatorI is a required interface of ShoppingCart. Statement (ii) is correct.

Consider the code below, implementing two components, Ermintrude and Oonator3000. Oonator3000 provides the oo() service to Ermintrude. Please modify the class Ermintrude to make its required interface explicit. You can simply cross out the code line(s) that need to be modified and provide the modified code line next to it. Hint: very few modifications are needed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public interface ICow { 
public moo();
}

public interface IOonator {
public oo();
}

class Ermintrude implements ICow {
private Oonator3000 _oonator;
Ermintrude (Oonator3000 oonator) {
_oonator = oonator;
}
moo() {
m();
_oonator.oo();
}
m() {
...}
}

class Oonator3000 implements IOonator {
oo() {
...}
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public interface ICow { 
public moo();
}

public interface IOonator {
public oo();
}

class Ermintrude implements ICow {
private IOonator _oonator;
Ermintrude (IOonator oonator) {
_oonator = oonator;
}
moo() {
m();
_oonator.oo();
}
m() {
...}
}

class Oonator3000 implements IOonator {
oo() {
...}
}

Replace Oonator3000 with IOonator in the Ermintrude class.


Modularity

Crosscutting

  • 1 Requirement impacting many modules
  • Non-functional (quality) requirements tend to result in cross-cutting
    • Quality requirements require multiple changes e.g. increase performance among code
img

Tangling

  • Too many requirements impacting one module
  • Non-functional (quality) requirements also tend to result in Tangling
    • Different Quality requirements require changes on the same code (e.g. performance, code readability)
img

Cohesion = measure of coherence among the pieces in a module

Coupling = measure of connectedness among modules

  • We want high cohesion and low coupling

Cohersion

Good Cohersion (High):

  • Functional cohersion (code are grouped by the same topic)

Bad Cohersion (Low):

  • Accidental conhersion
    • grouping code by random, lack of clear design
  • God object / class / module
    • too much functionality
    • can be break down into multiple modules
    • only can be justified when it is Math Helper class / Utility class
  • Temporal cohesion
    • grouping code by execution stage, the division of execution stage would lead to code duplication across modules
  • Control Flow cohesion
    • occurs when code is merged into a single module to share a common control flow
    • too many flags in a method

Coupling

(From Best (Low Coupling) to Worst (High Coupling))

  • No Coupling
  • Data Coupling
    • module A provides data to module B;
  • Stamp Coupling
    • passing too much data (pass unecessary data)
  • Control Coupling
    • module A controls the execution (such as control flow inside) of module B;
  • Location Coupling
    • module A is aware of the location (local or remote) of the target module B;
  • Content Coupling
    • module A includes code from module B, e.g., preprocessor includes, inheritance of implementation from superclass.

Which of these coupling types is highest?

  1. stamp
  2. data
  3. control

control.

Consider two modules: Application and File. File provides three operations: open file, read data from file, and close file; data can only be read after opening a file and before closing it. Application reads data from File by following the File interface. Which of these coupling types does the interaction between Application and File establish?

  • (i) stamp
  • (ii) control and data
  • (iii) data only
  • (iv) control only

(ii) control and data.

(Cohesion) The Linux kernel configuration tree gathers all multi-media devices in one group, even though they (mostly) do not interact with each other. What is the likely reason for such grouping?

They are grouped by their function (by topic)

Functional cohersion

(Cohesion) Please give an example of a god class that may be justified?

  • Math Help Library class
  • Utility class
  • Generated code

(Cohesion/Coupling) Give two different disadvantages of maintaining duplicate code in a system.

  • Could forget to propagate an error fix
  • Twice as much code to read and maintain

(Cohesion/Coupling) What is a potential disadvantage of factoring out common code into a common module?

  • Increased coupling (components or projects sharing code have to coordinate)
  • Increased testing effort (If multiple project share the common code rather than their own copies, changes to the common code driven by one project will trigger retesting all projects)

(Coupling) Suppose that procedure ProcessRequest() calls procedure ProcessElement(Element element, bool isVerbose), where isVerbose determines whether the ProcessElement is executed silently on element or whether each step within ProcessElement is logged. Name the two types of coupling that exist between these two procedures?

Data and control

Because “isVerbose determines whether the ProcessElement is executed” (Control) and “each step within ProcessElement is logged” (Data)

(Coupling) Which of the three types of coupling, namely control, data, and stamp coupling, is the lowest one?

(From Best (Low Coupling) to Worst (High Coupling))

  • No Coupling
  • Data Coupling
    • module A provides data to module B;
  • Stamp Coupling
    • passing too much data (pass unecessary data)
  • Control Coupling
    • module A controls the execution (such as control flow inside) of module B;
  • Location Coupling
    • module A is aware of the location (local or remote) of the target module B;
  • Content Coupling
    • module A includes code from module B, e.g., preprocessor includes, inheritance of implementation from superclass.

Therefore its data coupling

(Coupling) Name two different disadvantages caused by stamp coupling.

  • Increased security risk (the extra data is now also exposed)
  • Imprecise interface (does not make clear what the real dependency is)

When is a class a god class?

A class that has too many methods / too much code / too many responsibilities / does too much / …

Design Patterns

  • Composite Pattern
    • When to use: Tree structure / Uniform structure
    • Objects must be composed recursively
img
  • Decorctor Pattern
    • When to use: Wrapper (Add functionality)
      • identity crisis
img
  • Adapter Pattern
    • When to use: Borrowing function from another component
img
  • Template Method

    • Inheritance with subclass
      • fragile base class problem
  • Strategy Pattern

    • When to use: common interface to run different algo
    • Inheritance and allow multiple algorithms in a common interface
img
  • Observer Pattern
    • When to use: keep track of something (e.g. MVC)
    • If one object change, other objects are notified and change
img
  • Abstract Factory Pattern
    • When to use: different look and feel
    • Modularize an object to hide the concrete class and allow changing of a family of objects
img

What is the main difference between composite and decorator in terms of their class structure? (one line of text should suffice)

Composite can have many components;

Decorator just one (1-to-1 relationship)!

What is the main difference between decorator and adapter? (one line of text should suffice)

Adapter changes the interface of the wrapped component

Decorator keeps it unchanged

Consider the UML class diagram below.

img

img

Consider the class diagram below.

img

Name the relationship between A and B:

Composite

What is incorrect about it?:

Cardinality next to the black diamond should not be 2

Why?:

A child object can be component of at most 1 object at a time (no sharing)

img

Which design pattern suffers from the fragile base class problem?

Template Method. It is because Template Method relies on a base class.

Suppose that you are developing a graphical user interface library. The library will provide different kinds of widgets, including a text box (displaying text), a list box (displaying a list), and a combo box (displaying several widgets contained in it). What design pattern would you use to create the class hierarchy for the widgets? Please draw the resulting class diagram.

img

Extend the diagram from the previous question with two more widgets: scroll bars (adding scroll bars to any widget) and frame (adding a frame to any widget). What design pattern would you use for this extension? You don’t need to redraw the whole class diagram from the previous question; repeat only the class(es) necessary to do the extension.

img

What design pattern has been applied in the class diagram below?

img
  • Notice the sign “Wrapper”.
    • It is Decorator!
    • Could it be Adapter? No, because there is no borrowed class function.

Imagine that you are implementing a file system. The main abstractions in your design would be files and directories. Directories can contain zero or more files or directories. You want to treat directories and files in a uniform way as nodes, e.g., both will have name, date of creation, and content, and will provide operations to read and write content, and to list children. What design pattern could be used to achieve this design?

  • Notice the sign “uniform structure”.
    • It is Composite!
    • File and Directory will inherit from Node. Directory will be connected to Node using composition (black diamond), with Node being part Directory

Imagine that you would like to add the concept of symbolic links (also known as “shortcuts”) to the file/directory structure from the previous question. It should be possible to create symbolic links to files and directories. A symbolic link should be usable in just the same way as the file or directory that the link points to. What design pattern could be used to achieve this design?

  • Notice the sign adding new functionality.
    • It is Decorator!
    • Note that Decorator is 1-to-1 relationship

Refactoring

  • Sample code smells
    • Large method (function)
      • Solution: pulled out methods + Refactoring Switch
    • Large class (“God class”)
    • Data clamps
    • Excessive method chain
    • Duplicate Code
    • Comment
      • Solution: pulled out methods
    • Switch Statement
      • Solution: Strategy design with subclass
    • Magic number
    • Primitive obession
      • Solution: Introduce classes

What do you have to have in place as part of your project in order to perform refactorings with confidence?

Unit Tests.

Architectual Pattern

  • Layered Architecture

    • Topology

      • Stack, Tree, DAG
    • Pure Form

      • +ve: portability
    • Cross-Layer Optimization form

      • +ve: improve performance
      • -ve: Reduces portability / maintainability
  • Dependency Inversion

    • Dependency only allow from higher layer to lower layer
    • To achieve inversion:
      • Move the lower class to aside
      • Create an interface in the lower package
      • Inheritance to the interface

imgimg

  • Tiered Architecture

    • UI, Business Logic, Data
    img
  • Implicit Invocation (implemented through Observer Pattern)

    • Publish-Subscriber
    img
    • Model-View-Controller

1: Consider the following UML class diagram representing a layered system.

img

1a: What constraint of the layered architecture style does this design violate?

dependency directions only allow from high-level to lower-level.

1b: What refactoring can you apply to eliminate this violation?

Dependency Inversion!

1c: Please draw the resulting design after applying the refactoring?

  • Step1: Move the InBox to the left
  • Step2: Make a interface
  • Step3: connect InBox function to the interface
img

2: Consider the following specifications of application logic and classify it as business or UI control logic.

  • 2a: Customer should not be able to withdraw money if the account balance less than or equal zero.

    Business Logic

  • 2b: Pushing the save button will open a transaction and save the current customer and update the customer list on the screen.

    UI control logic

  • 2c: The withdraw button should be disabled when the customer is not allowed to withdraw money.

    UI control logic

3: Why it is a good idea to separate UI control logic, business logic, and data base access code?

Scalability. Since UI control logic, business logic, and database access code evolve at different speeds.

Each of them evolves at different speed in response to different forces (e.g., UI control logic depends on usability and UI technology (mobile vs. desktop); business logic evolves as business rules change; data base evolves as the data model changes and as the data base schema is optimized).

4: What are the two key advantages of using the layered architecture pattern?

  • Improved understandability of the system
  • Flexibility (layer reconfiguration: layers can be replaced)

1. Improved understandability of the system by allowing higher level functionality to be expressed in terms of lower-level functionality

2. Improved modifiability, esp. portability, as layers can be replaced

5: Consider the layered architecture below:

img

5a: What is the topology of this architecture (stack, tree, or DAG)?

DAG

5b: Note the L-shaped Hardware layer. What is the technical term for this arrangement?

Cross-layer optimization

5c: Note the L-shaped Hardware layer. What is the main reason to use this arrangement?

improve performance;
provide access to special features

5d: Note the L-shaped Hardware layer. What is the main disadvantage of this arrangement?

reduced modifiability

6: How a view is typically invoked in MVC?

By Implicit Invocation from the model

7: Consider the following system:

  • development environment capable of integrating a set of tools (e.g., compiler, editor, debugger, etc.) produced by different vendors; as an example of such interaction, stepping through a program in the debugger should automatically position the editor on the source line being executed;

7a: Which architectural pattern is most appropriate for the given system?

Publish-subscribe (or implicit invocation)

7b: Sketch the resulting architectural view.

img

7c: Give the reason for selecting a given pattern for the given system. List possible disadvantages (if any) for the given choice.

The publish-subscribe style allows plugging together independently developed components as long as there is some agreement on the type of events published and consumed. For example, stepping through the debugger can generate the event step; the editor can subscribe to this event and position the source code correctly after receiving each step event.

  • Allows plugging together independently developed components on a topic
  • Difficult to debug

The main disadvantage of publish subscribe architectures is that they are difficult to debug.

8: Consider the following system:

  • Online-banking web application with graphical user interface, business logic, and data base.

8a: Which architectural pattern is most appropriate for the given system?

Tiered Architecture (3-layer )

8b: Sketch the resulting architectural view.

img

8c: Give the reason for selecting a given pattern for the given system. List possible disadvantages (if any) for the given choice.

Online banking is a typical example of an enterprise application with GUI, business logic, and DB. These three components should be separated since they usually evolve at different speeds.

  • Evolve at different speeds
  • Does not support application integration well

The basic three-tier architecture does not support application integration well. Service layer, publish-subscribe facility, messaging, and REST help address this shortcoming.