02 DesignConcepts
02 DesignConcepts
Module Overview
Software
Design
Design
Patterns
Concepts
CONTEXT FOR SOFTWARE DESIGN
Software Design – Where does it fit?
// Authenticate user
printf(“Enter username:”);
scanf(“%s”,uname);
So, what’s wrong with this
printf(“Enter password:”); code?
scanf(“%s”,passwd);
status = AUTH_PENDING;
if( !strcmp(passwd,”#343idsk”))
status = “AUTH”;
else
status = “AUTH_FAIL”;
Example: First design then code
Design Code
1. Create a table in database
{
with username and // …
password printf(“Enter username:”);
2. Check password for given scanf(“%s”,uname);
username against password printf(“Enter password:”);
stored in the database scanf(“%s”,passwd);
status = AUTH_PENDING;
status = authenticate_user(uname, passwd);
// …
}
This is code with a proper
int authenticate_user(char u[], char pass[])
design looks much better, isn’t
{
it? // actualpass = select pass from user where uname = u
if( !strcmp(pass,actualpass) )
status = “AUTH”;
else
status = “AUTH_FAIL”;
return status;
}
Example: Architecture + Design + Code
Architecture (Principles!) Design
1. Applications must not implement 1. Accept userid / password from user
their own user management 2. Invoke authentication_service
code
2. All applications must only use a
centralized LDAP-based service
for both authentication and
authorization
3. ActiveDirectory-based services Code
are to be used
{
// …
printf(“Enter username:”);
Ah, thanks to the architecture scanf(“%s”,uname);
principles, NONE of my printf(“Enter password:”);
applications need to scanf(“%s”,passwd);
status = AUTH_PENDING;
implement authentication logic
status = authentication_service(uname, passwd);
// …
}
The Big Questions
Key drawbacks
RDD Strategy
of RDD
Architecture-Driven Design (ADD)
ADD Key
Strategy drawbacks
What is the verdict?
C – ????
Architecture
ADC – ????
AC AD
AC – ???? ADC
• Performance
• Security
Quality •
•
Scalability
Usability
Attributes • Maintainability
• Flexibility
Achieving Correctness
• What is correctness?
• How to incorporate correctness into design?
• How to incorporate correctness into code?
Achieving Correctness
What is robustness?
• Ability to be resilient when there are errors
Benefits
Watch out
• Coupling-Cohesion tradeoff
• More coding, more documentation
• More testable units, more bug possibilities
• Performance impact due to long call-chains
Reusability
What is reusability?
Benefits
Watch out
What is coupling?
High coupling
Low coupling
Reference:
https://www.javatpoint.com/software-engineering-coupling-and-cohesion
Types of coupling
• Data coupling
– Data is passed around for “information processing”
• Stamp coupling
– Passing large objects across modules (‘god object’)
• Control coupling
– One module’s data is used to drive execution control
• External coupling
– Dependency on external formats, protocols, services
• Common coupling
– Impacted by a common global data item
• Content coupling
– Inverse of control coupling (conditional branching into other modules)
Cohesion
What is cohesion?
Benefits
• Improves consistency
• Increase reuse
• Plug-and-play
• Engineering eases (development and testing)
• Localization of expertise
Watch out
Incremental
Templates and
Decomposition Composition and
Patterns
evolutionary
Decomposition
Decomposition Example
Solve sub-problems
• Check-sums of packs
• Encryption of packs
Similar to decomponsition
approach but solutions are
assembled incrementally.
Templates and Patterns
Pattern Repository Design
Pattern #1
Configure Design for
Pattern #2
Problem #1
Pattern #3
Pattern #4
Configure Design for
Problem #2
Patterns
Design Architecture
Patterns Patterns
Design Patterns
• Incorporates best practices to achieve design
goals
• Each pattern satisfies one or more design goals
• Learning to use design patterns involves:
– Learning how to implement the pattern
– Learning to identify which pattern to use when
Patterns in Architecture
Persistent Concurrent Lots of UI
Lots of Data
Data Users Screens
• Distilled wisdom
• Learnt and perfected over years
• Expressed in Problem / Solution format
• Alexander, Christopher (1977).
A Pattern Language: Towns, Buildings, Constructio
n
Recap: Software Design
Information
Classes and hiding with Overriding
Subclasses
objects Access methods
Specifiers
Generalization
Members Interface for
vs
Variables client access
Specialization
Single vs
Methods
Multiple
Design Principle Examples
• Identify the aspects that vary and separate them
from what stays the same
• Classes should be open for extension and closed
for modification
• Code using abstractions not on the concrete
GOING FORWARD
Looking ahead