25T2 Week 8
Friday 1-2pm (F13A)
Start 1:05pm
Software architecture defines the fundamental structure of a software system.
Software architecture defines the fundamental structure of a software system.
Why is it important to learn software architecture?
Influences software's adaptability, scalability, performance and maintainability
Software Architecture is like designing a blueprint for a garden.
Architectural style → Overall layout of a garden
Architectural components → Grouping of like plants
Class files in components → Individual plants within a group
Gardens are influenced by weather in the same way a software architecture is influenced by changes in
technology, deployment, etc.
A sequence diagram is an interaction diagram showing the temporal order of interactions between objects or components to achieve a specific functionality or use case
When would you choose to use a Sequence Diagram instead of a UML Class Diagram?
Actor: External user or system
Objects: Entities of the system
Lifelines: shows object existence during interactions
Messages: Communication between objects
Activation boxes: indicates active processing of messages
Sender waits for the receiver to complete the operation and return a response before continuing its own execution
Sender does not wait for the receiver to complete the operation; it sends the message and continues its own execution
alt represents alternate scenarios
loop represents repeated actions
We can create our sequence diagram by through Mermaid code and/or with Excalidraw
Sequence diagrams are often criticised for becoming unreadable in complex systems. What are some techniques to manage this complexity?
Helps teams visualise and communicate the software architecture of a system at different levels of abstraction.
The C4 Model includes 4 core diagrams:
These diagrams are a way to create "maps of your code" at different levels of detail, like zooming in and out on Google Maps
Shows the system as a "box" and its interactions with users and external systems
We can see the external users and systems represented as the different countries
Who is the intended audience for the Context Diagram in the C4 model?
It communicates the scope and external dependencies of the system in a simple and accessible way.
Breaks the system into containers (applications/services/databases) and shows how they interact.
Why separate the web frontend and backend service into different containers?
Zooms into a specific container to show its internal components and their relationships.
How does a Container Diagram differ from a Component Diagram?
Container
Component
Offers a detailed view of the source code structure (e.g., classes and interfaces) within a component.
Our UML diagrams :)
* If you are interested, not part of this course
class IntegerBox {
private Integer value;
public void shoutValue(Integer value) {
System.out.println(value.toString().toUpperCase + "!");
}
}class StringBox {
private String value;
public void shoutValue() {
System.out.println(value.toString().toUpperCase + "!");
}
}IntegerBox
StringBox
What are some design problems with this code?
class IntegerBox {
private Integer value;
public void shoutValue(Integer value) {
System.out.println(value.toString().toUpperCase + "!");
}
}class StringBox {
private String value;
public void shoutValue() {
System.out.println(value.toString().toUpperCase + "!");
}
}IntegerBox
StringBox
What are some design problems with this code?
What is it?
Style of programming that allow types to be used as a parameter to methods, classes and interfaces.
What is it?
Style of programming that allow types to be used as a parameter to methods, classes and interfaces.
Why would you use it?
public class Box<T> {
private T value;
public Box(T value) {
this.value = value;
}
public void setValue(T value) {
this.value = value;
}
public T getValue() {
return value;
}
}
public class Box<T, S> {
private T value1;
private S value2;
public Box(T value1, S value2) {
this.value1 = value1;
this.value2 = value2;
}
public void setValue(T value1, S value2) {
this.value1 = value1;
this.value2 = value2;
}
public T getValue1() {
return value1;
}
public S getValue2() {
return value2;
}
}
Inside src/stack, there are a series of stubs for a Stack class which takes in a generic type. There are a series of tests inside StackTest.java which currently fail.
Implement the methods so that the tests pass, using an ArrayList to store the internal data structure.
Iterable
Iterable are objects that can be iterated over. Iterator
public interface Iterator<T> {
boolean hasNext();
T next();
void remove();
}Iterator
public interface Iterable<T> {
Iterator<T> iterator();
}public interface Iterator<T> {
boolean hasNext();
T next();
void remove();
}hasNext(): Returns true if iteration has more elements afternext(): Returns next element of iterationremove(): Removes from the collection the last element return by the iteratorpublic static Integer sumStack(Stack<? extends Integer> stack);
<? extends Type> and <? super Type> mean??? is called a wildcard and represents an unknown type. Provides flexibility for methods that accept a range of types