SC2006 Notes
SC2006 Notes
2024年8月12日 8:35
分区 新分区 1 的第 1 页
LEC-2 Requirements Elicitation
2024年8月15日 13:46
Requirements Elicitation:
Eliciting stakeholder needs and desires through:
○ Interview
○ Observation
○ Workshop
○ Legacy Product Study
○ Competitive Product Study
○ Prototype
• Learn problem domain, Study user tasks
Types of Requirements:
• Functional requirements: (The things that the system must do)
Describe interactions between the system and the environment
i.e., to map program inputs to program outputs
○ E.G.
▪ System functionality to be performed:
□ The library member must be able to search the library catalog
□ The bank customer must be able to withdraw cash from the ATM
▪ Information to be processed:
□ The system must display the current time in 24 hour format
□ The system must display the temperature in degrees centrigrade in the
range -10°C to +130°C to one decimal place of accuracy
▪ Interface with other systems:
□ The system must be able to use wifi to communicate all transactions with a
clients secure database
□ The system must be able to control up to six robot arms simultaneously
• Non-Functional requirements:
Describe the properties the system must have
Not directly related to the functional behaviour of the system
分区 新分区 1 的第 2 页
○ Not directly related to the functional behaviour of the system
○ E.G.
Usability Help messages must be displayed in the local language
according to the user’s locale
i.e. User friendliness
Reliability After a system reboot, the full system functionality must be
restored within 5 minutes
Consistency, accuracy
Performance When a book is placed in the checkout pad, the system must
detect it within 2 seconds
i.e. Response time
Supportability The database must be replaceable with any commercial product
supporting standard SQL queries
Scalability Up capacity easily
Maintainability Easy to restart/restore
Security Authentication
Requirements Validation:
• Stakeholders – the system specified meets their needs and desires (i.e. correct) and
requirements are prioritized
• Development Team – requirements (and underlying assumptions) are properly understood
• Review:
○ Walkthrough, inspection, critical review
○ Checklist for completeness, consistency, unambiguity, correctness
• Prototype
○ Still images
分区 新分区 1 的第 3 页
○ Interactive prototype:
Illustrates some simulated dialogue
Data Dictionary:
The problem domain glossary
NO implementation terms
• Ensures consistent unambiguous terminology that all stakeholders can agree
○ E.G.
Programme of Study, Course, Degree Programme
• Ensures specialised terms are defined
○ E.G.
Lecture, Tutorial, Cohort, Laboratory, Seminar
• E.G.
Term Definition
Program of A university program that a student enrolls into. There are three levels of
Study programs: undergraduate, master, and PhD
Semester There are four semesters in an academic year. Semester 1 and Semester 4
have 13 teaching weeks. Semester 2 and Semester 3 have 5 teaching
weeks
Course A course is a basic unit of teaching. A course must be either compulsory
or elective. A course must include lectures and tutorials. Some courses
may have labs
Lecture The traditional form of class that are delivered in lecture theaters. Each
lecture will be video recorded and published in the learning management
system
Tutorial The interactive, small-size classes that are conducted in technology-
enhanced tutorial rooms. Tutorials will not be video recorded
分区 新分区 1 的第 4 页
LEC-3 Use Case Diagram
2024年8月18日 20:46
分区 新分区 1 的第 5 页
• E.G.
○ Extends:
Adding optional functionality
i.e. Extends the functionality in the original problem statement
▪ Extends are only used in the parent Use Case in exceptional or unusual
circumstances
▪ E.G.
"ReportEmergency" is complete by itself, but can be extended by
分区 新分区 1 的第 6 页
"ReportEmergency" is complete by itself, but can be extended by
use case "Help" for a scenario in which the user requires help
分区 新分区 1 的第 7 页
分区 新分区 1 的第 8 页
LEC-4 Use Case Description
2024年8月19日 16:40
Each Use Case Must have a Use Case Description that contains:
• Participating Actors (incl. Initiating Actor):
○ A use case can have more than one participating actors
○ Initiating actor triggers the use case
○ If the use case is triggered by a system event or another use case, the initiating actor is
NULL
• Entry conditions (Pre-condition):
The system state must be satisfied to execute a use case
• Exit Conditions (Post-condition):
The system state must be reached after executing a use case
• Flow of Events (AKA Normal or Main Successful Flow):
○ Step #1 - How Actor triggers the use case
○ Step #2 - How System responds
○ Step #3 - ...
• Alternative Flows:
○ Variations or errors in the interaction (e.g. wrong username/password)
○ Return back to the normal flow of events
• Exceptions:
Exceptional situations that cause the failure of the use case (e.g. network not available)
分区 新分区 1 的第 9 页
○ EX1: If the Bank Customer enters invalid PIN for three times
i. The ATM displays the message “Card is suspended! Please call the customer
service (1633) to reactive the card” for 2 seconds
ii. The ATM outputs the card
○ EX2: If the ATM has insufficient funds
i. The ATM displays the message “This ATM is off-service due to insufficient
funds!” at the start screen
ii. The ATM does not accept the card
分区 新分区 1 的第 10 页
8. If the Registrar selects the activity QUIT, the system returns to the semester selection
screen.
分区 新分区 1 的第 11 页
LEC-5 Conceptual Models
2024年8月20日 16:37
Conceptual Model:
• Objects:
Anything that has a state and exhibits behavior
○ E.G.
Bus, Dog, Company, LoginForm, UserVerifier, UserList
• Operations:
Procedures through which objects communicate amongst themselves
○ E.G.
Bus: Stop, Start
Dog: Bark, Growl
Company: Sell, Quote
LoginForm: submit
UserVerifier: autheticate
UserList: SearchUser
• Attributes:
Variables that hold state information
○ E.G.
Bus: Seats, Colour
Dog: Name, Breed
Company: Name, Employees
Class Diagrams:
• Represent the structure of the system
• The classes define the responsibilities for doing various activities
• Used during:
○ requirements analysis: model application domain concepts
○ system design: model subsystems
○ object design: specify the detailed behavior and attributes of classes
• Classes:
○ A class represents a concept
A class encapsulates states (attributes) and behaviour (operations)
分区 新分区 1 的第 12 页
○ A class encapsulates states (attributes) and behaviour (operations)
▪ Each attribute has a type
▪ Each operation has a signature
• Associations:
○ Denote relationships between classes
○ The multiplicity of an association end denotes how many objects the instance of a class
can legitimately reference:
▪ A number (e.g. 3)
▪ A range of numbers (e.g. 1..6)
▪ Unspecified number / Many (*)
○ E.G.1 (1-to-1)
○ E.G.2 (1-to-Many)
○ E.G.3 (Many-to-Many)
Class Relationships:
• Generalization:
Inheritance relationship
○ Inheritance between classes
○ Interface implementation
○ Hierarchies drawn top-down with arrows pointing upward to parent
○ Line/arrow styles differ:
▪ class: solid line, black arrow
▪ abstract class: solid line, white arrow
▪ interface: dashed line, white arrow
分区 新分区 1 的第 13 页
• Association:
Usage relationship
○ Dependency ("uses temporarily"):
▪ Often is an implementation detail, not an intrinsic part of that object's state
▪ Dotted line
分区 新分区 1 的第 14 页
b. Real-world entities the system must track
c. Application (problem) domain terms in data dictionary
2. Find the attributes for each Class
3. Find the methods/operations for each Class
4. Find the associations between Classes
Stereotypes of Classes:
• Boundary Class <<boundary>>:
Interaction between Actor & System
分区 新分区 1 的第 15 页
分区 新分区 1 的第 16 页
LEC-6 Sequence Diagram & Communication Diagram
2024年8月21日 15:18
Sequence Diagram:
Used during requirement analysis:
○ To refine use case descriptions
○ Find additional/missing objects
1. Objects are represented by rectangles
2. Messages are represented by arrows
3. Activations are represented by narrow bars
4. Lifelines are represented by dashed lines
• Captures how a group of objects (in a Class Diagram) interact or collaborate to achieve a use
case scenario
Usually captures the dynamics of a single scenario, the sequence of messages that are
passed between the objects, and the sequence of events that happen during the
scenario
• Emphasise the time ordering of calls and messages
• Types of Interaction Frames:
sd sequence diagram
ref reference another sequence diagram
loop the actions loop until guard condition is false
(as in while, for)
opt/alt optional/alternative flow
(as in if-then, if-then-else, switch-case)
par each action is run in parallel
• E.G. (EnterSecureFacility Use Case Description)
○ Identify important verbs in flow of events:
1. User presses finger on FingerprintReader
2. FingerprintReader scans fingerprint and sends image to the FacilityAccessSystem
3. The FacilityAccessValidator finds fingerprint in the EmployeeList
4. The FacilityAccessSystem validates fingerprint and unlocks EntryGate
5. …
○ Draw sequence diagram:
分区 新分区 1 的第 17 页
○ Refine Use Case Description:
▪ Flow of Events:
1. User presses finger on FingerprintReader
2. FingerprintReader scans fingerprint and sends image to the
FacilityAccessSystem
3. The FacilityAccessValidator finds fingerprint in the EmployeeList
4. If the fingerprint image is found in the employee list, the
FacilityAccessValidator unlocks EntryGate
5. …
▪ Alternative Flows:
□ AF-4. If the fingerprint image is not found in the employee list
1. FingerprintReader displays a “Please try again” message
2. Go back to Step 1
○ Refine Sequence Diagram:
Communication diagrams:
• Emphasise the communication links between the objects
• Represents a combination of information taken from Class, Sequence, and Use-Case Diagrams
describing both the static structure and dynamic behavior of a system
• Messages are labeled with a chronological number
分区 新分区 1 的第 18 页
• E.G.1
• E.G.2
分区 新分区 1 的第 19 页
LEC-7 Dialog Map (FSM) & Activity Diagram (Flowchart)
2024年8月26日 18:01
• Transition:
○ Assumed to be instantaneous in response to an event
○ Optionally have:
▪ event: event triggers the transition
▪ guard: the condition which must be true to take the transition
▪ action: action to do during the transition
○ UML:
• Most systems will have a finite number of states in which it can be depending on the previous
state AND actions which move it to another state
• E.G.
A 2-bit binary counter has 4 states and moves from one state to the next when a clock
signal drives it to the next state
分区 新分区 1 的第 20 页
• E.G.2 (Dialog Map of Student Management System)
Rounded
rectangle
Control flow between activities
Arrow
Control flow that has one input and multiple outputs (go to concurrent
activities)
Fork
Multiple control flows come together into a single control flow
Join
When control flow can go in one of several directions depending on a
分区 新分区 1 的第 21 页
When control flow can go in one of several directions depending on a
condition
Decision box
(branch)
Merge several branches into one branch
Merge branches
• E.G.1 (Activity Diagram of Do Laundry)
分区 新分区 1 的第 22 页
• E.G.3
• E.G.4
分区 新分区 1 的第 23 页
State Machine Diagram vs. Activity Diagram:
• Activity diagrams:
○ Used as a flow chart of activities performed by the system
○ Describe the workflow behavior of a system in terms of activities
• State machine diagram:
○ Models a system or an object based on the “States” it can be in
分区 新分区 1 的第 25 页
LEC-8 Software Processes
2024年8月26日 20:11
分区 新分区 1 的第 26 页
○ The waterfall model is mostly used for large systems engineering projects where a
system is developed at several sites
In those circumstances, the plan-driven nature of the waterfall model helps
coordinate the work
分区 新分区 1 的第 27 页
○ Faster delivery and deployment of system
○ Reuse is now the standard approach for building many types of business system
○ Key Stages:
▪ Requirements specification
▪ Software discovery and evaluation
▪ Requirements refinement
▪ Application system configuration
▪ Component adaptation and integration
○ Types of reusable software:
▪ Stand-alone application systems (AKA COTS or Commercial-Off-The-Shelf
systems) that are configured for use in a particular environment
▪ Collections of objects that are developed as a package to be integrated with a
component framework like .NET or J2EE
▪ Web services that are developed according to service standards and which are
available for remote invocation
○ Problems:
▪ Requirements compromises are inevitable so system may not meet real needs of
users
▪ Loss of control over evolution of reused system elements
• In practice, most large systems are developed using a process that incorporates elements from
all of these models
分区 新分区 1 的第 28 页
LEC-9 Agile Software Development Process
2024年9月2日 12:38
Agile development:
• Program specification, design and implementation are interleaved
• The system is developed as a series of versions or increments with stakeholders involved in
version specification and evaluation
• Frequent delivery of new versions for evaluation
• Extensive tool support used to support development
○ E.G.
automated testing tools
• Minimal documentation
Focus on working code
分区 新分区 1 的第 29 页
• To reduce overheads in the software process (e.g. by limiting documentation) and to be able
to respond quickly to changing requirements without excessive rework
• Focus on the code rather than the design
• Based on an iterative approach to software development
• Intended to deliver working software quickly and evolve this quickly to meet changing
requirements
分区 新分区 1 的第 30 页
• Practices:
Principle or Description
practice
Incremental Requirements are recorded on story cards and the stories to be
Planning included in a release are determined by the time available and their
relative priority. The developers break these stories into development
'Tasks'
Small The minimal useful set of functionality that provides business value is
Releases developed first. Releases of the system are frequent and incrementally
add functionality to the first release
Simple Design Enough design is carried out to meet the current requirements and no
more
Test-first An automated unit test framework is used to write tests for a new
Development piece of functionality before that functionality itself is implemented
Refactoring All developers are expected to refactor the code continuously as soon
as possible code improvements are found. This keeps the code simple
and maintainable
Pair Developers work in pairs, checking each other’s work and providing
Programming the support to always do a good job
Collective The pairs of developers work on all areas of the system, so that no
Ownership islands of expertise develop and all the developers take responsibility
for all of the code. Anyone can change anything
Continuous As soon as the work on a task is complete, it is integrated into the
Integration whole system. After any such integration, all the unit tests in the system
must pass
Sustainable Large amounts of overtime are not considered acceptable as the net
Pace effect is often to reduce code quality and medium term productivity
On-Site A representative of the end-user of the system (the customer) should
Customer be available full time for the use of the XP team. In an extreme
programming process, the customer is a member of the development
team and is responsible for bringing system requirements to the team
for implementation
分区 新分区 1 的第 31 页
○ User story:
○ Task cards:
Refactoring:
• Conventional wisdom in software engineering is to design for change. It is worth spending
time and effort anticipating changes as this reduces costs later in the life cycle
XP, however, maintains that this is not worthwhile as changes cannot be reliably
anticipated
• XP proposes constant code improvement (refactoring) to make changes easier when they
have to be implemented
Programming team look for possible software improvements and make these
improvements even where there is no immediate need for them
• This improves the understandability of the software and so reduces the need for
documentation
• Changes are easier to make because the code is well-structured and clear
• However, some changes requires architecture refactoring and this is much more expensive
• E.G.
○ Re-organization of a class hierarchy to remove duplicate code
○ Tidying up and renaming attributes and methods to make them easier to understand
○ The replacement of inline code with calls to methods that have been included in a
program library
Test-first development:
• Testing is central to XP and XP has developed an approach where the program is tested after
every change has been made
• XP testing features:
○ Test-first development
○ Incremental test development from scenarios
○ User involvement in test development and validation
Automated test harnesses are used to run all component tests each time that a new
分区 新分区 1 的第 32 页
○
○ Automated test harnesses are used to run all component tests each time that a new
release is built
• Writing tests before code clarifies the requirements to be implemented
• Tests are written as programs rather than data so that they can be executed automatically
○ The test includes a check that it has executed correctly
○ Usually relies on a testing framework such as Junit
• All previous and new tests are run automatically when new functionality is added, thus
checking that the new functionality has not introduced errors
• E.G. (Test case description for dose checking)
Test automation:
• Test automation means that tests are written as executable components before the task is
implemented
○ These testing components should be stand-alone, should simulate the submission of
input to be tested and should check that the result meets the output specification
○ An automated test framework (e.g. Junit) is a system that makes it easy to write
executable tests and submit a set of tests for execution
• As testing is automated, there is always a set of tests that can be quickly and easily executed
○ Whenever any functionality is added to the system, the tests can be run and problems
that the new code has introduced can be caught immediately
Pair programming:
• In pair programming, programmers sit together at the same computer to develop the software
• Helps develop common ownership of code and spreads knowledge across the team
○ The sharing of knowledge that happens during pair programming is very important as it
reduces the overall risks to a project when team members leave
• It serves as an informal review process as each line of code is looked at by more than 1 person
• Pairs are created dynamically so that all team members work with each other during the
development process
• Pair programming is not necessarily inefficient and there is some evidence that suggests that a
pair working together is more efficient than 2 programmers working separately
分区 新分区 1 的第 33 页
Scrum:
An agile method that focuses on managing iterative development rather than specific agile
practices
• Three phases in Scrum:
○ Outline planning phase:
▪ Establish the general objectives for the project
▪ Design the software architecture
○ Sprint cycles:
▪ Each cycle develops an increment of the system
○ Wrap-up:
▪ Completes required documentation
□ E.G.
System help frames and user manuals
▪ Assesses the lessons learned from the project
Scrum terminology:
Scrum term Definition
Development • A self-organizing group of software developers, which should be <= 7
team people
• Responsible for developing the software and other essential project
documents
Potentially • The software increment that is delivered from a sprint
shippable • "potentially shippable" means that it is in a finished state and no further
product work, such as testing, is needed to incorporate it into the final product
increment • In practice, this is NOT always achievable
Product • A list of "to do" items which the Scrum team must tackle
backlog • The single source of requirements for any changes to be made to the
product
• May be feature definitions for the software, software requirements, user
stories or descriptions of supplementary tasks that are needed, such as
architecture definition or user documentation
Product • An individual (or a small group) who identifies product features or
owner requirements, prioritize these for development and continuously review
the product backlog to ensure that the project continues to meet critical
business needs
• Can be a customer but might also be a product manager in a software
company or other stakeholder representative
Scrum • A daily meeting of the Scrum team that reviews progress and prioritizes
work to be done that day
• Ideally, this should be a short face-to-face meeting that includes the whole
team
ScrumMaster • Responsible for ensuring that the Scrum process is followed and guides the
team in the effective use of Scrum
• Responsible for interfacing with the rest of the company and for ensuring
that the Scrum team is not diverted by outside interference
• Scrum developers are adamant that the ScrumMaster should not be
thought of as a project manager. Others, however, may not always find it
easy to see the difference
Sprint • A development iteration
• Sprints are usually 2-4 weeks long
Sprint backlog • The set of Product Backlog items (PBls) selected for the Sprint, plus a plan
for delivering the product increment and realizing the Sprint Goal
• The sprint backlog is unchanged during the period of the Sprint
• Items not "Done" by end of the Sprint will be added back to the Product
分区 新分区 1 的第 34 页
• Items not "Done" by end of the Sprint will be added back to the Product
Backlog and addressed during the next Sprint
• Any improvements needed can be put back to the Product Backlog:
Either add additional Sprints to the schedule or remove lower priority
items from the Product Backlog
Velocity • An estimate of how much product backlog effort that a team can cover in a
single sprint
• Understanding a team’s velocity helps them estimate what can be
covered in a sprint and provides a basis for measuring improving
performance
Teamwork in Scrum:
• The ‘Scrum master’ is a facilitator who arranges daily meetings, tracks the backlog of work
to be done, records decisions, measures progress against the backlog and communicates with
customers and management outside of the team
• The whole team attends short daily meetings (Scrums) where all team members share
information, describe their progress since the last meeting, problems that have arisen and
what is planned for the following day
This means that everyone on the team knows what is going on and, if problems arise,
can re-plan short-term work to cope with them.
Scrum benefits:
• The product is broken down into a set of manageable and understandable chunks
• Unstable requirements do NOT hold up progress
• The whole team have visibility of everything and consequently team communication is
improved
• Customers see on-time delivery of increments and gain feedback on how the product works
• Trust between customers and developers is established and a positive culture is created in
which everyone expects the project to succeed.
分区 新分区 1 的第 35 页
LEC-10 UMLs
2024年9月9日 14:14
分区 新分区 1 的第 36 页
ii. Identify the main Use Cases (action verbs)
II. Generate initial Use Case descriptions
分区 新分区 1 的第 37 页
ii. Refine Use Case descriptions
□ E.G.
ValidateDoorEntry Use Case Description
Flow of Events:
1. Employee presses finger on FingerprintReader.
2. FingerprintReader scans fingerprint (using use case Scan
fingerprint) and sends image to the FacilityAccessManager.
3. The FacilityAccessManager validates the fingerprint
4. If fingerprint is valid display the message “Please enter” and
unlock the EntryGate.
1. 4.1 The EntryGate sends a signal to the
FacilityAccessManager that it has opened and closed.
2. 4.2 The FacilityAccessManager locks the EntryGate, and
logs the entry time and name of the employee who
entered in the entry log.
Alternative Flow:
1. AF-S4. If fingerprint is not valid display the message “Access
denied” and log the attempted entry time in the entry log.
IV. Generate Class Diagram
i. Identify Classes
分区 新分区 1 的第 38 页
V. Add Sequence Diagrams
分区 新分区 1 的第 39 页
VIII. Review Requirements and Refine Use Cases & Diagrams
▪ Iteratively refine the Class Diagram and Sequence Diagram
▪ This may involve some refinement of the Use Cases
▪ Repeat until the Functional Requirements of the System are fully specified
分区 新分区 1 的第 40 页
LEC-11 Data Access Object Pattern
Tuesday, 1 October 2024 1:24 pm
分区 新分区 1 的第 41 页
LEC-12 System Architecture Design
2024年9月30日 19:39
分区 新分区 1 的第 42 页
▪ Robustness
▪ Security
▪ Maintainability
• Design Principles:
○ E.G.
▪ Modularity
▪ Abstraction
▪ Open-Closed
▪ Reusability
• Design Patterns:
○ E.G.
▪ Layered Architecture
▪ Client and Server
▪ Data Centered
• Constraints:
○ E.G.
▪ Languages
▪ Libraries
▪ Communications
▪ MVC
○ A set of connectors:
▪ Subroutine calls, remote procedure calls, data streams, and sockets
○ A topological structure
○ A set of semantic constraints:
▪ Specifies how to determine a system's overall properties from the properties of its
parts
▪ Filters in a pipe-and-filter architecture do not share states with each other
▪ One layer can only call the service provided by the lower layer in a layered system
• One of the hallmarks of software architectural design is the use of idiomatic patterns of
system organization
• Ambiguity in a Software Architectural Style:
○ Number of components involved:
▪ E.G. (pipe-and-filter architecture)
□ 2 filters connected by 1 pipe; or
□ 20 filters connected by 19 pipes
○ Mechanism of interaction:
▪ E.G. (layered system)
□ The call to the lower layer can be:
分区 新分区 1 的第 43 页
□ The call to the lower layer can be:
local procedure calls, or remote procedure calls, or other process
communication mechanisms
○ Function of the system and components:
One of the components in an architectural style may be a database, but the kind
of data may vary
Layered Architecture:
• Pros:
○ Better security
○ Scalability
○ Simple maintenance
○ Easily enhanced
• Cons:
○ Dependency Issue:
One layer can only call the service provided by the lower layer
• E.G. (3-Layered Arch)
分区 新分区 1 的第 44 页
• E.G. (Android)
分区 新分区 1 的第 45 页
LEC-13 Object Design Patterns
Tuesday, 1 October 2024 12:20 pm
Object Design:
• Interface Specification:
Operations, arguments, type signatures, and exceptions
• Reuse:
Existing libraries and Design Patterns
• Restructuring:
To meet the design goal maintainability, flexibility…
• Optimization:
Speed or memory
Design Pattern:
A proven solution to a problem in a context
• Abstracts a recurring design structure
• A template with class and/or object:
○ Dependencies
○ Structures
○ Interactions; or
○ Conventions
• Four Elements of a Design Pattern:
○ Name:
Describes the pattern
▪ Adds to common terminology for facilitating communication (i.e. not just sentence
enhancers)
○ Problem:
Describes when to apply the pattern
○ Solution:
Describes elements, relationships, responsibilities, and collaborations which make
up the design
○ Consequences:
Results of applying the pattern
分区 新分区 1 的第 46 页
Results of applying the pattern
▪ Benefits and Costs
▪ Subjective depending on concrete scenarios
Strategy Pattern:
• Design Problem:
A set of algorithms or objects should be interchangeable
• E.G.
• Pros:
○ Provides encapsulation
○ Hides implementation
○ Allows behavior change at runtime
• Cons:
○ Results in complex, hard to understand code if overused
分区 新分区 1 的第 47 页
are / how observers will do with the changes
○ Observer does NOT constantly check the changes
○ Defines a one-to-many dependency between objects so that when one object changes
state, all of its dependents are notified and updated automatically
▪ Easy Subscription and Automatic Notification
• How:
○ Subscription mechanism:
▪ Observers freely register/unregister their interests in Subject
○ Notification mechanism:
▪ Subject propagates the change to Observer when the change occurs
• Pros:
○ Abstracts coupling between Subject and Observer
○ Supports broadcast communication
○ Enables reusability of subjects and observers independently of each other
• Cons:
○ Slower performance
○ If not used carefully the observer pattern can add unnecessary complexity
• Pull Update Template:
分区 新分区 1 的第 48 页
• Pull Update vs Push Update:
○ Pull update:
▪ Subject sends simple notification (via Observer.update())
▪ The Observer calls back (via Subject.getData()) for details explicitly (if
Observer is interested)
▪ Two way communication
○ Push update:
▪ Subject sends detailed information about the change (or update), regardless of
Observer wants it (interested) or not
▪ Observer does NOT need to call back
▪ One way communication
• Interest Subscription + Selective Notification Template:
• Event Handling:
An implementation of observer pattern
○ E.G. (Java Swing Event Handling)
分区 新分区 1 的第 49 页
分区 新分区 1 的第 50 页
LEC-14 Factory & Façade Design Patterns
2024年10月9日 14:46
• When To Use?
○ When you have a set of classes but don't know exactly which one to instantiate until
runtime
○ When you need to create one of several classes that implement a common superclass
without exposing the creation logic to the client
○ When you want to localize the logic to instantiate objects
• Design Problems:
Decouple class selection and object creation (abstract instantiation process) from the
client where the object is used
○ Existing subclasses can be replaced, and new subclasses can be added
○ Process of selecting subclass to use and creating object can be complex
○ Client does not know in advance which class will be used, and the class can be chosen at
runtime
• "Standard" Version (Template):
Context uses StaticFactory to obtain an object that implements
AbstractProduct interface
○ E.G.
分区 新分区 1 的第 51 页
• Benefits:
○ Encapsulate object creation:
▪ Remove duplicate object creation code from clients
▪ Centralize class selection and object creation code
○ Easy to extend, replace, or add new subclasses:
▪ Replace MySQLImpl1 with MySQLImpl2
▪ Support new OracleImpl
○ Easy to change object creation logic:
▪ Support Singleton单例 object
▪ Support lazy initialization
• Strategy + Factory + Dynamic Loading:
○ Create any subclass object without specifying the class name in the code
○ No need to change a single line of code to use new classes
○ Provide the foundation for modern software frameworks to load application-specific
classes
○ E.G. (Extending Eclipse IDE)
分区 新分区 1 的第 52 页
○ E.G. (JDBC Database Driver)
Façade Pattern:
Provides a unified interface for a set of interfaces in a subsystem
Defines a higher level interface that makes the subsystem easier to use
• Design Principles:
○ Identify the aspects of your application that vary then separate them from what stays
the same
○ Program to an interface, not an implementation
○ Favor composition over inheritance
○ Strive for loosely coupled designs between objects that interact
○ Classes should be open for extension, but closed for modification
○ Principle of least knowledge – talk only to your immediate friends
• Pros:
Makes code easier to use and understand
分区 新分区 1 的第 53 页
○ Makes code easier to use and understand
○ Reduces dependencies on classes
○ Decouples a client from a complex system
• Cons:
○ Results in more rework for improperly designed Façade class
○ Increases complexity and decreases runtime performance for large number of Façade
classes
• E.G.
○ Non-Façade:
○ Façade:
分区 新分区 1 的第 54 页
LEC-15 MVC Design Pattern
2024年10月9日 15:56
○ Update Worksheet:
分区 新分区 1 的第 55 页
Model-View-Controller (MVC) Architecture:
• Main Goal:
○ To facilitate and optimize the implementation of interactive intensive systems,
particularly those that use multiple synchronized presentations of shared information
• Key Idea:
○ The separation of the Model from View and Controller components allows multiple
Views of the same Model
It separates presentation and interaction from the data
▪ If the user changes the Model via the Controller of one View, all other Views
dependent on this data should reflect the changes
• Separation of UI from the core data model:
○ Need to support multiple different UI's and core functionality should be reusable across
all different interfaces
▪ E.G.
desktop GUI, browser, PDA, cell phone, etc.
○ Interface details changes frequently:
▪ Changing UI details should not affect core functionality
○ It should be easy to add a new UI
• MVC Components:
○ Encapsulate core Functionality (App Logic) + Data in Model
○ Implement UI in View (present data) + Controller (react to user input)
Model Contains the processing (operations) and the data involved
View Presents the output – Defines and manages how the data is presented to
the user
• Each View provides specific presentation of the same Model
• Each View "observes" the Model Whenever the data Model changes,
all Views immediately notified and so they can update their graphical
presentation
Controller Manages user interaction – Captures user input (events -> mouse clicks,
key presses, etc.) and passes these interactions to the View and the Model
• Each View is associated to a Controller that captures and processes
user input and modifies the data Model
• The user interacts with the system solely through Controllers
• Controllers typically implement event-handling mechanisms that are executed when
corresponding events occur
• Changes made to the Model by the user via Controllers are directly propagated to the
分区 新分区 1 的第 56 页
• Changes made to the Model by the user via Controllers are directly propagated to the
corresponding Views
The change propagation mechanism can be implemented using the observer pattern
(via subscribe/notify protocol)
• MVC architecture style is non-hierarchical (triangular):
○ View subscribes for changes to the Model (via Observer subscription mechanism)
○ Controller gathers input (or change) from the users and updates the Model
○ Model updates the change and notifies all subscribers (the Views) of the change (via
Observer notfication mechanism)
○ View is notified and updates its display; the user sees the change
• Design Patterns in MVC:
○ Observer Pattern (View-Model, Controller-Model):
▪ Model uses the Observer Pattern to keep the View(s) updated
▪ When Model (Subject) data is changed, it updates all the Views (Observers, via
notification mechanism)
▪ Allows multiple Views to the same Model
○ Strategy Pattern (View-Controller, View-Look & Feel):
▪ View and Controller use the Strategy Pattern as the View is concerned with the
visual aspects (display data) and delegates the interface behaviors to the
Controller
▪ The View (Context) uses the Controller (Strategy Interface) to implement a specific
type of response (or strategy objects)
▪ The Controller can be changed to allow View to respond differently to user input
○ Abstract Factory:
▪ Create Controller or Look & Feel for a View
○ Composite:
▪ Nested views
▪ E.G.
Panel containing Button; Nested Panels
○ Decorator:
▪ Attach additional UI functionalities to a view
▪ E.G.
Scrolling
○ Command:
▪ Support undo/redo user actions
分区 新分区 1 的第 57 页
• Pros:
○ Simultaneous development
○ Multiple views for a model
○ High cohesion:
▪ MVC enables logical grouping of related actions on a controller together
The views for a specific model are also grouped together
○ Low coupling:
▪ The very nature of the MVC framework is such that there is low coupling among
models, views or controllers
• Cons:
○ Code navigability and pronounced learning curve:
▪ The framework navigation can be complex because it introduces new layers of
abstraction and requires users to adapt to the decomposition criteria of MVC
○ Multi-artifact consistency:
▪ Decomposing a feature into three artifacts causes scattering
▪ Thus, requiring developers to maintain the consistency of multiple representations
at once
分区 新分区 1 的第 58 页
LEC-16 Testing
Tuesday, 15 October 2024 9:44 am
Software Bug:
An error, flaw, failure or fault in a computer program or system that causes it to produce an
incorrect or unexpected result, or to behave in unintended ways
Testing:
• To show the presence of bug
• To reduce the perceived risk of system not working to an acceptable value
• To result in low-risk software without much testing effort
• NOT to show the absence of bug
• NOT equals debugging
• NOT to show that software works
Levels Of Testing:
• Unit testing:
Test an unit individually
• Integration testing:
Test units in combination
• System testing:
Test everything (functionality, usability, reliability, performance, portability, security, ...)
• Acceptance testing (UAT, User Acceptance Testing):
Customer accepts the software and give us money
Types Of Testing:
• Black Box Testing:
○ What to analyze:
Requirements and specifications
▪ E.G.
"The income of an applicant must be between $1500 and $8000 per month"
○ Black Box Testing Process:
• The tester:
1. Analyzes requirements or specifications
equivalence classes and boundary values
2. Chooses valid inputs and invalid inputs
3. Determines expected outputs (oracle) for chosen inputs
4. Constructs tests with the chosen inputs
▪ E.G.
write JUnit program
• The testing engine:
1. Executes the tests
2. Compares actual outputs (log) with the expected outputs (oracle)
3. Determines whether the SUT (System Under Test) functions properly
○ Types of black box testing:
▪ Equivalence class testing and boundary value testing
▪ State-based testing
○ Applicability:
All testing levels (Unit, Integration, System, Acceptance)
○ Pros:
○ Directs the tester to a very small subset of test inputs that can highly likely find the
bugs
○ Cons:
○ Cannot know how much of the implementation have been tested
○ No notion of testing coverage like in white box testing
• White Box Testing:
分区 新分区 1 的第 59 页
• White Box Testing:
○ What to analyze:
Implementation details, internal paths and structure
○ White Box Testing Process:
• The tester:
1. Analyzes SUT's (System Under Test) implementation
▪ Control Flow Graph or Data Flow Graph
2. Identify execution paths through the SUT
3. Chooses inputs to cause the SUT to execute selected paths
4. Determines expected outputs (oracle) for chosen inputs
5. Constructs tests with the chosen inputs
• The testing engine:
1. Executes the tests
2. Compares actual outputs (log) with the expected outputs (oracle)
3. Determines whether the SUT (System Under Test) functions properly
○ Type of white box testing:
▪ Basis Path Testing (Control flow testing, structured testing)
▪ Data flow testing
○ Applicability:
All testing levels (Unit, Integration, System, Acceptance)
○ Pros:
○ Ensure that every path through the SUT has been identified and tested
○ Cons:
○ Testing all execution paths is generally infeasible
▪ E.G.
loop, number of decision points
○ May not detect data and arithmetic bugs
▪ E.G.
a = a - 1 // should be a = a + 1
a/b // b cannot be zero
○ Never find paths that are not implemented
▪ E.G.
paths in requirements are missing in implementation
分区 新分区 1 的第 60 页
• E.G. (Android Unit Test Case)
分区 新分区 1 的第 61 页
LEC-17 Equivalence Class Testing
2024年10月21日 20:21
Defensive Testing:
Create test cases for both valid and invalid inputs
▪ NEVER assume that users will use your code in your expected way
▪ Test the module to see whether it behaves as expected for invalid inputs
i.e. NOT cause unexpected errors or abnormal behavior (sudden program termination)
分区 新分区 1 的第 62 页
• Design Test Cases Using ECs:
1. Test valid inputs of several parameters at the same time
i.e. each test case can have multiple valid inputs
▪ Choose one valid input for each input parameter from an equivalence class
2. Test ONLY one invalid input from an equivalence class of one input parameter at the
same time
i.e. each test case should have no more than one invalid input
▪ Choose valid inputs from an equivalence class of all other input parameters
▪ In this way we can focus on the only possible error caused by the single invalid
input
▪ E.G. (inappropriate test case)
分区 新分区 1 的第 63 页
LEC-18 Boundary Value Testing
2024年10月24日 11:02
E.G.1
Income range valid equivalence class (1500 ≤ x ≤ 80000):
○ Lower boundary: 1499, 1500, 1501
○ Upper boundary: 79999, 80000, 80001
○ Valid boundary values (on-the-boundary):
{1500, 80000}
○ Invalid boundary values (just-below and just-above):
{1499, 80001}
E.G.2
Number of mortgage valid equivalence class (0 ≤ x ≤ 5)
○ Lower boundary: -1, 0, 1
○ Upper boundary: 4 , 5, 6
○ Valid boundary values: {0, 5}
○ Invalid boundary values: {-1, 6}
E.G.3
Length of password valid equivalence class (4 ≤ x ≤ 8)
○ Lower boundary: 3, 4, 5
○ Upper boundary: 7, 8, 9
○ Valid boundary values: {4, 8}
○ Invalid boundary values: {3, 9}
E.G.4
0 - 15, 55 - 99 Do not hire
16 - 17 Part-time
分区 新分区 1 的第 64 页
18 - 54 Full-time
Do not hire (0 ≤ age ≤ 15):
○ Lower boundary: -1, 0, 1
○ Upper boundary: 14, 15, 16
Part time (16 ≤ age ≤ 17):
○ Lower boundary: 15, 16, 17
○ Upper boundary: 16, 17, 18
Full time (18 ≤ age ≤ 54):
○ Lower boundary: 17, 18, 19
○ Upper boundary: 53, 54, 55
Do not hire (55 ≤ age ≤ 99):
○ Lower boundary: 54, 55, 56
○ Upper boundary: 98, 99, 100
• Valid boundary values: {0, 15, 16, 17, 18, 54, 55, 99}
• Invalid boundary values: {-1, 100}
分区 新分区 1 的第 65 页
LEC-19 Control Flow Testing
2024年11月2日 18:43
Process Block:
A sequence of statements execute sequentially
• NOT contain if/while/for/switch/goto statements
They will manipulate the control flow and break the sequential execution
• Contains any number of sequentially executed statements in the process block
• One control flow edge directed into the process block
• One control flow edge directed out of the process block
• E.G.
分区 新分区 1 的第 66 页
Binary Decision Point:
Control flow can change at the decision point
• Two control flow edges directed out of the decision point:
○ True branch
○ False branch
• Loop back to the decision point from the last statement
• if statement:
• if-else statement:
• while statement:
• for statement:
分区 新分区 1 的第 67 页
N-ary Decision Point:
Control flow can change at the decision point
• One control flow edge directed into the decision point
• N control flow edges directed out of the decision point
• switch statement:
○ E.G.
分区 新分区 1 的第 68 页
• Level 2 - 100% Branch Coverage:
Create test cases such that all branches (edges) directed out of the decision points are
executed at least once under test
▪ Binary decision points all evaluate to TRUE and FALSE outcome once for each
○ E.G.
分区 新分区 1 的第 69 页
iv. Determines expected outputs (oracle) for chosen inputs
v. Constructs tests with the chosen inputs
○ The testing engine:
i. Executes the tests
ii. Compares actual outputs (log) with the expected outputs (oracle)
iii. Determines whether the SUT (System Under Test) functions properly
• Cyclomatic Complexity of a CFG:
Measures how complex your program is in terms of the number of decision points
i.e. if/while/for/switch
CC = |edges| - |nodes| + 2
CC = |decision| + 1, if all decision points are binary
○ CC ∝ # of decision points ∝ # of basis paths to test
▪ E.G.
If the program has CC value 6, then the tester has to identify 6 basic paths to
test
E.G.1
CC = |edges| - |nodes| + 2 = 8 - 7 + 2 = 3
CC = |decision| + 1 = 2 + 1 = 3
分区 新分区 1 的第 70 页
2) Create a Test Case for Each Basis Path:
○ One set of basis paths:
▪ 2-3, 4, 5, 7, 8, 11 (Baseline)
▪ 2-3, 4, 7, 8, 11
▪ 2-3, 4, 5, 7, 8, 9, 11
○ Three test cases:
▪ a = 4; b = 2
▪ a = 0; b = 5
▪ a = 7; b = 3
• The basis set is NOT unique, but each basis set has the same number of basis paths:
○ Another set of basis path:
▪ 2-3, 4, 7, 8, 11 (Baseline)
▪ 2-3, 4, 5, 7, 8, 11
▪ 2-3, 4, 7, 8, 9, 11
○ Three test cases:
▪ a = 0; b = 0
▪ a = 1; b = 0
▪ a = 0; b = 3
分区 新分区 1 的第 71 页
• Not All Basis Paths are Feasible:
○ One set of basis paths:
▪ 1, 2, 3, 4, 5, 6, 8 (Baseline)
▪ 1, 2, 4, 5, 6, 8 (infeasible)
▪ 1, 2, 3, 4, 5, 7, 8 (infeasible)
○ One feasible test case:
▪ a=4
▪ Infeasible basis path
▪ Infeasible basis path
• We need to minimize infeasible Basis Paths:
○ Another set of basis paths:
▪ 1, 2, 3, 4, 5, 6, 8 (Baseline)
▪ 1, 2, 4, 5, 6, 8 (infeasible)
▪ 1, 2, 4, 5, 7, 8 (change both decision points at the same time)
○ Two test case:
▪ a=4
▪ Infeasible basis path
▪ a=0
CC = |decision| + 1 = 2 + 1 = 3
Three basis paths:
○ 1, 2, 10 (Baseline, select false branch first)
○ 1, 2, 3, 4, 8, 2, 10
○ 1, 2, 3, 6, 8, 2, 10
Three test cases:
分区 新分区 1 的第 72 页
Three test cases:
○ n=0
○ n=1
○ n=4
Real execution paths:
○ 1, 2, 10
○ 1, 2, 3, 4, 8, 2, 10
○ 1, 2, 3, 4, 8, 2, 3, 4, 8, 2, 3, 4, 8, 2, 3, 6, 8, 2, 10
分区 新分区 1 的第 73 页
LEC-20 Software Maintenance
2024年11月5日 16:26
Software Maintenance:
The process of modifying a software system after delivery to:
correct faults, improve performance or other attributes, or adapt to a changed
environment
• Changes are implemented by modifying existing system components and/or adding new
components to the system
• Maintenance Effort Distribution:
Software Refactoring:
The process of making improvements to a program to slow down the structure and code
degradation through change. It means modifying a program to:
○ Improve its structure
○ Reduce its complexity
○ Make it easier to understand
• Refactoring does NOT change the behaviour or add functionalities to the software
分区 新分区 1 的第 74 页
• Refactoring does NOT change the behaviour or add functionalities to the software
• Refactoring is a continuous process of improvement throughout the development and
evolution process
• Refactoring is intended to avoid the structure and code degradation that increases the costs
and difficulties of maintaining a system
分区 新分区 1 的第 75 页