Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of Design Patterns to improve code maintainability #1

Open
amadoran opened this issue Dec 27, 2022 · 0 comments
Open

Use of Design Patterns to improve code maintainability #1

amadoran opened this issue Dec 27, 2022 · 0 comments

Comments

@amadoran
Copy link

Facade Pattern.
image

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:
image

Iterator Pattern.
image

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.
image

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:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant