COMP2511 Week 10
Agenda
- Admin Stuff
- Serverless Architecture
- Revision!
Admin Stuff
- Assignment 2 is due this Wednesday 3pm!
- Please complete the MyExperience ty :)
- We greatly appreciate all your feedback
- For the sample exam, please wait outside of the lab for us to log into the exam environment
Congrats on also making it to the end of the term!

Serverless Architecture
Serverless
Definition: Allows developers to build and run applications without managing infrastructure
- Apps are built as a collection of functions deployed to a cloud provider who automatically provision, scale and manage the infrastructure
- Code is deployed as small, stateless functions (FaaS) which are triggered by events (e.g. HTTP request, file upload)

Serverless
- Developers only need to worry about writing code and are billed for execution time, to the millisecond


Explain how serverless functions could be used in an IoT health monitoring system.
IoT devices i.e. smart watches can send users' health data to the cloud periodically (e.g. this is why it takes a while to sync your fitness data between devices).
Each incoming data packet can trigger a serverless function that checks the data for anomalies such as a dangerously high heart rate and sends a push notification to the user.



Revision
Finding Patterns
Code and Design Smells
Code Smells
A code smell is a surface indication that usually corresponds to a deeper problem in the system.
An good list of most code smells are in Refactoring Guru. You will be tested on identifying different code smells in the assignment and final exam!
In groups, let's discuss the following examples. Identify the code smells and any underlying design problems associated with them.

Code Smell #1
Mark, Bill and Jeff are working on a PetShop application. The PetShop has functionality to feed, clean and exercise different types of animals. Mark notices that each time he adds a new species of animal to his system, he also has to rewrite all the methods in the PetShop so it can take care of the new animal.
- Code Smell: Divergent Change
-
Design Problem:
- Open-Closed Principle
- Low Cohestion
- How to fix: Delegate behaviour away to relevant classes which adhere to single responsibility (e.g. Strategy, Abstract Factory, etc.)
Code Smell #2
public class Person {
private String firstName;
private String lastName;
private int age;
private int birthDay;
private int birthMonth;
private int birthYear;
private String streetAddress;
private String suburb;
private String city;
private String country;
private int postcode;
public Person(String firstName, String lastName, int age,
int birthDay, int birthMonth, int birthYear,
String streetAddress, String suburb, String city,
String country, int postcode) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.birthDay = birthDay;
this.birthMonth = birthMonth;
this.birthYear = birthYear;
this.streetAddress = streetAddress;
this.suburb = suburb;
this.city = city;
this.country = country;
this.postcode = postcode;
}
// Some various methods below
// ....
}
- Code Smell: Data clumps, long parameter list
- Design Problem: DRY and KISS
- How to fix: Refactor by making more classes for birthday and address ("Extract Class"/ "Introduce Parameter Object")
Code Smell #3
public class MathLibrary {
List<Book> books;
int sumTitles {
int total = 0
for (Book b : books) {
total += b.title.titleLength;
}
return total;
}
}
public class Book {
// Our system just models books as titles
// (content doesn't matter)
Title title;
}
public class Title {
int titleLength;
int getTitleLength() {
return titleLength;
}
void setTitleLength(int tL) {
titleLength = tL;
}
}
-
Code Smell:
- Inappropriate intimacy (accessing public fields)
- Message chaining (Law of Demeter)
- Data/Lazy classes
- Design Problem: High coupling from encapsulation being broken
-
How to fix:
- Make attributes private and use getters and setters
-
BookandTitlecan be one class
Code and Design Smells
How do these code smells cause problems when developing code?
Affects the reusability, maintainability and extensibility. How fast does it take for a new developer to understand what is happening?
Is a code smell always emblematic of a design problem?
No - e.g "switch statements" and "comments" are often listed as code smells but are not always actually smells
Kahoot
COMP2511 Tutorial 10
By rebeccahsu
COMP2511 Tutorial 10
- 387