Categories
Sin categoría

HFOOAD Chapter 5 – Flexible

Change – my experience

This chapter is all about change. Sometimes change to your code can be relatively easy. Sometimes, you feel like you broke your application entirely. I think one basic type of change is just refactoring your code. For example: I am currently working in an app. I’m in charge of the API. I use MySQL so I write a lot of queries. Most of them are simple. However, there are some queries that require a lot of other quieres.

In the beginning I only had simple queries, so when a query was succesfully made I made a callback function to retrieve the data from the query. When you have multiple queries this starts to become really messy. A calback function within a callback function within a calback function is not easy to read or to debug. The obvious solution was using async await. This really made the code a lot easier to read and debug.

This chapter

This chapter also dives into class diagrams. It talkes about concepts that are really useful to keep in mind. Such as aggregation. I like the cheat sheet that the book includes. I helps you contextualize UML in an eviromnent that I’m used to work in.

Aggregation

The book uses the concept of aggregation. It is shown when the UML of ricks program is described. To say that something is an agregation of another thing the line with the diamond is used. Agregation is an association. It means that something is made up (in part) of another thing. The example that the book uses is with the instrument astract class. The concept of an abstract class will be explained shortly. An instrument (in ricks program) has assigned to it an InstrumentSpec. Because an instrumetn needs specifications in ricks program. To be precise one instrumentSpec.

Abstract Class

An abstract class is a generalization of a class. It means that it has subclasses that share a common behaviour with eachother. It’s important to note that an abstract class should not be instantiated. It is just used as a common template between classes. The example that the book gives is with the instrument. A mandolin has a lot of similarities with a guitar. So the abstract class from which both classes inherit from is instrument. An instrument alone can’t be an object. You need to specify what instrument.

Leave a comment