High-Level Design Flashcards
(43 cards)
Abstraction
Abstraction is a technique for managing complexity by focusing on relevant details and hiding unnecessary ones. It allows engineers to concentrate on what’s important for a specific task (e.g., a UX designer focuses on UI flows, not backend cryptography).
Data Abstraction
explicitly separating the abstract properties of a data type and its concrete implementation
What makes
createTeam(name: string): boolean
an example of data abstraction?
It hides the implementation details of how teams are created and stored. Client code only interacts with the method’s contract (what it requires and what it provides), not with the underlying data or logic
data abstraction
- obscuring data so the client code is oblivious to the underlying implementation
- ex:
// Creates a new team.
// Requires: A non-empty and unused name.
// Modifies: Team database.
// Effects: Returns whether a team was created.
public createTeam(name: string):boolean {…}
control abstraction
- Control abstraction means hiding the how of program execution so developers can focus on the what.
- It lets programmers write logical, readable code without worrying about low-level machine operations.
- Control statements (if, for, while)
- Functions/methods
- javascript promises
top down decoposition
- cons: might not match the best design in practice
Bottom Up Composition
as you create types, find layers of abstraction above them
Information Hiding
- hide specific details of implementation
- ex: create a private field that can only be accessed by instances of the class that it is in
Encapsulation
- encapsulate the data and behaviour of a class and seperate it from its implementation
- abstracts away info and simplifies
problems with coupling (4)
- eaasier for errors in one part of the system to propagate to other parts of the system
- increases the degree to which a single bug fix or addition is scattered across the code base
- harder to reuse independently
- harder to understand a coupled element because it cannot be considered/understood independently
ways to decrease coupling (3)
- Minimize the number of interfaces between elements
- Minimize the complexity of interfaces
- Avoid control flow coupling
draw flow chart for coupling
answer in notes
Data Coupling (score)
- coupling through primitive types
- score: 1
Stamp Coupling
- coupling through data scructures
- score: 2
Control Coupling
- coupling through control flags (the example given is a boolean about status)
- score: 3
Global Coupling
- use of global variables
- score: 4
Content Coupling
- coupling through internal sccess
- score: 5
Draw the Cohesion Flow Chart
in notes
cohesion + pros/cons
Cohesion measures how focused a program element (especially a class) is on doing a single, complete task.
In object-oriented design, cohesion evaluates how well the elements within a class belong together.
- cons: Can make navigation harder
pros: But makes individual classes easier to understand and maintain
Helps with:
Debugging
Feature additions
Bug fixes
low cohesion
- Class performs many unrelated tasks.
- Leads to conflicting concerns within the same class.
- Harder to reason about and maintain:
- Fixing one bug may break a feature that relies on different logic in the same class.
- As a class’s scope grows, the chance of these issues increases
high cohesion
- Class has a clear purpose and a unified set of responsibilities.
- Typically has:
- A small set of private fields
- Fields that are used by most public methods
- If some fields are used only by a few methods, that may suggest non-cohesive design.
sequential cohesion
- output from one step is used as input in the next step
- score: 2
communicational cohesion
- when different tasks are grouped together because they work on the same data
- score 2
procedural cohesion
- when rasks are related by control flow, harder to independantly reuse
- score 3