Congrats on also making it to the end of the term!
Definition: Allows developers to build and run applications without managing infrastructure
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.
Finding Patterns
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.
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.
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
// ....
}
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;
}
}
Book and Title can be one classHow 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