PadhaikoAll subjects

Architectural Design

Software Engineering (ENCT 352)

Open in the Padhaiko app

4.1 Introductions and importance

Definition

Software Architecture

The software architecture of a program or computing system is the high-level structure of the system, comprising software components, the externally visible properties of those components, and the relationships (connectors) among them.

Architectural design represents the bridge between requirements engineering and detailed component-level design. Before writing code or designing individual algorithms, engineers establish the system's overall blueprint.

Why Software Architecture Is Important

According to Bass, Clements, and Kazman (and Pressman), architectural design is crucial for three primary reasons:

  1. Mutual Communication Among Stakeholders: Architecture provides a common, high-level abstraction that customers, project managers, security auditors, and developers can all inspect, critique, and negotiate early.
  2. Early Design Decisions & Quality Attribute Enforcement: Fundamental quality attributes—such as performance, scalability, availability, security, and maintainability—are largely determined by the architecture and are extremely costly to retrofit later.
  3. Transferable Abstraction (Large-Scale Reuse): A well-documented architecture serves as an intellectual asset that can be reused across a product line of systems sharing similar requirements.

4.2 Architectural design principles

Effective software architectures obey a core set of engineering design principles:

Fundamental Principles of Architectural Design
PrincipleMeaning and Practical Benefit
1. Separation of ConcernsDivide complex problems into distinct parts (e.g., presentation, business logic, data persistence) so each concern can be reasoned about and modified independently.
2. AbstractionFocus on essential external behavior and interfaces while hiding internal implementation details at higher architectural levels.
3. Information Hiding (Parnas)Encapsulate volatile design decisions (data formats, algorithms, hardware interfaces) behind stable interfaces so internal changes do not ripple outward.
4. ModularityPartition software into separately named, addressable components (modules) that integrate to satisfy problem requirements.
5. Functional IndependenceDesign each module to perform one well-defined task with minimal interaction with other modules (high cohesion, low coupling).
6. Refinement & RefactoringElaborate top-level architectural abstractions stepwise into detailed structures, continuously simplifying internal structure without changing external behavior.
7. Design for Change & ScalabilityAnticipate growth in user load, new integrations, and shifting business rules through loose interfaces and stateless components where possible.

4.3 Taxonomy of architectural styles

An architectural style is a recurring structural pattern describing a family of systems in terms of component types, connectors, semantic constraints, and topological layout.

Common Architectural StylesText
(a) Data-Centered (Repository)        (b) Pipe-and-Filter (Data Flow)
       [ Client ]  [ Client ]           [Source] -> |Filter A| -> |Filter B| -> [Sink]
            \        /
       [ Shared Repository ]          (c) Layered Architecture
            /        \                  [ Presentation / UI Layer ]
       [ Client ]  [ Client ]           [ Application / Logic Layer ]
                                        [ Data Access / OS Layer    ]
Taxonomy of Software Architectural Styles
Architectural StyleComponents & ConnectorsStrengthsWeaknesses / Best Fit
1. Data-Centered (Repository / Blackboard)Central data store (DB or shared blackboard) accessed by independent client componentsEasy data sharing, centralized backup/security, easy to add new clientsCentral repository can become a bottleneck or single point of failure; best for databases, IDEs, compilers
2. Data-Flow (Pipe-and-Filter)Filters transform input streams into output streams; pipes carry streams sequentiallyReusable filters, intuitive composition, supports concurrent streamingPoor for interactive UIs; overhead from parsing/serializing streams; best for Unix shells, compilers, ETL pipelines
3. Call-and-Return (Main-Subroutine / OO)Hierarchical procedures or objects invoking methods via function/RPC callsClear control flow, straightforward debugging and decompositionTight call dependencies if interfaces change; best for standard desktop and OO business apps
4. Layered (Virtual Machine)Concentric or stacked layers where layer calls only layer Clean separation of concerns, layer portability and swap-abilityLatency overhead across layers; strict layering sometimes bypassed; best for OS kernels, TCP/IP, enterprise N-tier web apps
5. Event-Driven (Publish-Subscribe)Producers emit events to an event bus; subscribers react asynchronouslyVery loose coupling, easy to attach new reactions dynamicallyHarder to trace end-to-end execution order and debug race conditions; best for GUIs, IoT, real-time notifications
6. Client-Server & N-TierClients request services over a network from specialized servers (Web, App, DB tiers)Centralized security/data control, independent hardware scalingNetwork latency and partial failures; best for web portals, banking systems, multi-user SaaS

4.4 Modular design, cohesion and coupling

Modular design achieves functional independence—considered the single most important indicator of good software design—by maximizing cohesion within each module and minimizing coupling between modules.

AspectCohesionCoupling
DefinitionDegree to which elements inside a single module belong together functionallyDegree of interdependence between two or more separate modules
Design GoalMaximize (High cohesion is desirable)Minimize (Low / loose coupling is desirable)
Effect on MaintenanceHigh cohesion makes a module focused, readable, and easy to reuseLow coupling limits ripple effects when one module is modified

Levels of Cohesion (Worst to Best)

Seven Levels of Module Cohesion (Lowest to Highest)
RankCohesion TypeDescriptionQuality
1 (Worst)CoincidentalUnrelated tasks grouped arbitrarily in one module (e.g., a catch-all miscUtils())Avoid
2LogicalLogically similar operations placed together, selected by a control flag (e.g., handleAllIO(type))Poor
3TemporalTasks grouped only because they run at the same time (e.g., startupInit() resetting logs, DB, UI)Fair / Weak
4ProceduralElements grouped because they follow a fixed execution sequence, though acting on different dataModerate
5CommunicationalElements operate on the same input or output data structure (e.g., validate and format a student record)Good
6SequentialOutput data from one element directly serves as input to the next element (pipeline inside module)Very Good
7 (Best)FunctionalEvery element contributes to one single, well-defined task (e.g., computeGPA(grades))Ideal

Levels of Coupling (Worst to Best)

Six Levels of Module Coupling (Highest/Worst to Lowest/Best)
RankCoupling TypeDescriptionQuality
1 (Worst)Content CouplingOne module directly modifies or branches into the internal data or code of another moduleAvoid
2Common CouplingMultiple modules read and write the same shared global data areaPoor
3External CouplingModules share an externally imposed data format, communication protocol, or device interfaceFair
4Control CouplingOne module passes a control flag telling another module how to execute internallyModerate
5Stamp CouplingModules share a composite data structure (e.g., whole Student object) when only a single field is neededGood
6 (Best)Data CouplingModules communicate solely by passing only the minimal primitive data parameters requiredIdeal

Structural Metrics: Fan-In and Fan-Out


Worked Examples

Example 4.1

4.1

A web application is designed using a strict Layered Architecture consisting of four layers: Presentation (), Business Logic (), Data Access (), and Database (). A proposed revision introduces an intermediate Security/Policy Proxy Layer that adds of processing per request.

  1. Compute the single-request end-to-end latency before and after adding the new layer, and find the percentage increase in latency.
  2. Explain the architectural trade-off between strict layering and performance.

Part 1 — End-to-End Request Latency: Original -layer latency:

Revised -layer latency (with the proxy layer):

Percentage increase in latency:

Part 2 — Architectural Trade-Off:

  • Benefit: Adding a dedicated security/policy layer improves separation of concerns, centralizes authentication/authorization checks, and isolates security rules from business logic.
  • Cost: Strict layering requires every request to traverse every layer boundary, introducing cumulative serialization, validation, and call latency ( here). Architects mitigate this by caching authorization tokens or allowing controlled read-only fast paths.
Answer:
  1. Latency rises from to , a increase.
  2. Strict layering enhances modularity and maintainability at the expense of inter-layer traversal latency.
Example 4.2

4.2

During an architecture review, an engineer inspects a billing module processOrder(orderRecord, modeFlag) that reads a global tax rate variable GLOBAL_TAX, prints an invoice, updates inventory, and emails a receipt depending on modeFlag.

  1. Identify the cohesion and coupling flaws in the current design.
  2. Suppose refactoring splits the design into three focused functions (calculateTotal(subtotal, taxRate), updateStock(itemId, qty), sendReceipt(email, invoiceId)), reducing total cross-module interface arguments/globals from () to (). Compute the percentage reduction in interface surface area and identify the improved cohesion and coupling levels.

Part 1 — Diagnosing Current Cohesion and Coupling Flaws:

  • Cohesion Flaw: Mixing invoice calculation, printing, inventory mutation, and email dispatch controlled by modeFlag yields Logical / Temporal Cohesion rather than single-purpose Functional Cohesion.
  • Coupling Flaws:
    • Reading GLOBAL_TAX introduces Common Coupling.
    • Passing modeFlag introduces Control Coupling.
    • Passing the entire orderRecord when only specific fields are needed introduces Stamp Coupling.

Part 2 — Quantitative Interface Reduction and Target Quality: Original interface dependencies items; refactored interface dependencies items:

Each refactored function performs one clear job (Functional Cohesion) and receives only minimal primitive values (Data Coupling).

Answer:
  1. The original design suffers from Logical/Temporal Cohesion plus Common (GLOBAL_TAX), Control (modeFlag), and Stamp (orderRecord) coupling.
  2. Refactoring reduces interface dependencies by (from to ) and achieves Functional Cohesion with Data Coupling.
Example 4.3

4.3

How to Answer a Past Exam Question: "Recommend and justify an architectural style for (a) a real-time stock-ticker alert platform and (b) a compiler / log-processing pipeline."

1. Stock-Ticker Alert Platform Event-Driven (Publish-Subscribe) Architecture:

  • Structure: Market feed producers publish price-change events to an event broker; portfolio watchers, threshold alert services, and audit loggers subscribe asynchronously.
  • Justification: Supports dynamic addition of new subscribers without modifying producers (loose coupling) and scales well under bursty real-time updates.

2. Compiler / Log-Processing Pipeline Pipe-and-Filter (Data-Flow) Architecture:

  • Structure: Sequential independent filters (e.g., Lexer Parser Optimizer Code Generator, or Log Collector PII Redactor Aggregator) connected by data streams.
  • Justification: Each filter is reusable, testable in isolation, and stages can execute concurrently as streams flow through.
Answer:

Match system characteristics to style strengths: use Event-Driven (Publish-Subscribe) for asynchronous reactive notifications and Pipe-and-Filter for sequential stream transformations.


Exercises

Practice Exercises — Architectural Design

Question 1

Define software architecture and explain three reasons why architectural design is vital before detailed coding begins.

Definition: Software architecture defines the high-level structural organization of a system: its components, their externally visible properties, and the connectors/relationships among them.

Three Reasons Architecture Matters:

  1. Stakeholder Communication: Provides a shared blueprint understandable by clients, managers, and developers.
  2. Early Quality-Attribute Decisions: Determines performance, security, availability, and modifiability early, when changes are cheapest.
  3. Large-Scale Reuse: Enables architectural patterns and skeletons to be reused across similar products.
Answer:

Software architecture is the blueprint of components, interfaces, and connectors. It is vital for stakeholder communication, enforcing early quality attributes, and enabling large-scale architectural reuse.

Question 2

Explain the architectural design principles of Separation of Concerns, Abstraction, Information Hiding, and Functional Independence.

Four Core Architectural Principles:

  • Separation of Concerns: Decompose the system into distinct concerns (e.g., UI, business logic, storage) so each evolves independently.
  • Abstraction: Expose essential component behavior while suppressing low-level implementation details.
  • Information Hiding: Encapsulate volatile design decisions behind stable module interfaces so changes stay localized.
  • Functional Independence: Give each module a single clear responsibility (high cohesion) and minimal inter-module reliance (low coupling).
Answer:

Separation of concerns isolates distinct responsibilities; abstraction hides unnecessary detail; information hiding shields volatile internals behind stable interfaces; functional independence ensures high cohesion and low coupling.

Question 3

Compare Data-Centered (Repository), Pipe-and-Filter, Layered, and Event-Driven architectural styles with one practical application for each.

Comparison of Four Architectural Styles:

  1. Data-Centered: Central repository accessed by multiple clients; easy data sharing, risk of central bottleneck (e.g., IDE metadata repository / banking database).
  2. Pipe-and-Filter: Independent stream-transforming filters connected by pipes; high filter reuse, weak for interactive UIs (e.g., Unix shell pipelines / compilers).
  3. Layered: Hierarchical layers where each layer serves the one above; clean separation, potential latency overhead (e.g., OSI/TCP-IP networking stack, enterprise web apps).
  4. Event-Driven: Components communicate asynchronously via published events; very loose coupling, harder execution tracing (e.g., GUI frameworks, microservice notification systems).
Answer:

Repository centralizes shared state (databases/IDEs); Pipe-and-Filter chains stream transformations (compilers/Unix tools); Layered separates abstraction levels (OS/network stacks); Event-Driven decouples producers and subscribers asynchronously (GUIs/real-time alerts).

Question 4

Distinguish between cohesion and coupling. Arrange the seven levels of cohesion and six levels of coupling from worst to best, and identify the ideal level of each.

Cohesion vs. Coupling:

  • Cohesion measures intra-module functional relatedness (goal: high).
  • Coupling measures inter-module dependence (goal: low).

Ordered Levels (Worst Best):

  • Cohesion: Coincidental Logical Temporal Procedural Communicational Sequential Functional (ideal).
  • Coupling: Content Common External Control Stamp Data (ideal).
Answer:

Cohesion measures internal unity (maximize; Functional is ideal) and coupling measures external interdependence (minimize; Data is ideal). Cohesion runs from Coincidental to Functional; coupling runs from Content to Data.

Question 5

A Pipe-and-Filter log analytics pipeline originally executes four sequential filters with processing times , , , and per batch. By refactoring two tightly coupled legacy helper modules into functionally independent filters and merging redundant parsing steps, the total pipeline latency drops from to .

  1. Verify the original pipeline latency and calculate the percentage reduction in processing time.
  2. Explain what fan-in and fan-out mean in modular design, and why minimizing common coupling improves testability.

Part 1 — Pipeline Latency and Percentage Reduction:

Part 2 — Fan-In, Fan-Out, and Common Coupling:

  • Fan-In is the number of modules calling a given module (high fan-in signals good reuse).
  • Fan-Out is the number of modules called by a given module (very high fan-out indicates excessive orchestration complexity).
  • Eliminating Common Coupling (shared mutable global state) ensures modules depend only on explicit parameters, allowing unit tests to run cleanly without hidden global side effects.
Answer:
  1. Original latency is , and refactoring achieves a reduction to .
  2. Fan-in counts incoming callers (reuse) while fan-out counts outgoing calls (complexity); removing common coupling eliminates hidden global state, making modules independently testable.
← Software Requirements EngineeringSystem Modeling (part 1: 5.1–5.2) →