You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The main motivation to use this pattern is that we are going to hide all the complexity of the system, and thus we only make use of it, for example, we see that this class accesses several attributes, but our user should not create one by one, It would be better to just make a class that is the facade and creates the rest.
Solution:
Iterator Pattern.
The main reason to use this design pattern is that if we look at this code snippet we will realize that they use a lot of "for" loops, and we are going to optimize this here using the "Iterator" design pattern, since We are going to iterate through each of the departments that exist.
Solution:
To show this solution using UML, we create the Seats, Flights classes, which will implement the IterableCollections interface with which we will do the iterations, then we create the respective iterator classes with their Iterator interface which is of the useful class and allows these classes are iterable. With this, the Seat and Flight classes are created, which will be the ones that contain these iterators.
Factory Method Pattern.
The main reason to use this design pattern is because of the scalability of the code. If we think about the future and part of what the owner of the repository tried to do, we will notice that there is a flaw when trying to classify in different types of flights. Therefore, we would have a flight with several types, which guides us to use the Factory design pattern, so we will create several types of flights and if another one appears, another one would be created and the code would not be modified.
Solution:
The text was updated successfully, but these errors were encountered:
Facade Pattern.
The main motivation to use this pattern is that we are going to hide all the complexity of the system, and thus we only make use of it, for example, we see that this class accesses several attributes, but our user should not create one by one, It would be better to just make a class that is the facade and creates the rest.
Solution:
Iterator Pattern.
The main reason to use this design pattern is that if we look at this code snippet we will realize that they use a lot of "for" loops, and we are going to optimize this here using the "Iterator" design pattern, since We are going to iterate through each of the departments that exist.
Solution:
To show this solution using UML, we create the Seats, Flights classes, which will implement the IterableCollections interface with which we will do the iterations, then we create the respective iterator classes with their Iterator interface which is of the useful class and allows these classes are iterable. With this, the Seat and Flight classes are created, which will be the ones that contain these iterators.
Factory Method Pattern.
The main reason to use this design pattern is because of the scalability of the code. If we think about the future and part of what the owner of the repository tried to do, we will notice that there is a flaw when trying to classify in different types of flights. Therefore, we would have a flight with several types, which guides us to use the Factory design pattern, so we will create several types of flights and if another one appears, another one would be created and the code would not be modified.
Solution:
The text was updated successfully, but these errors were encountered: