Copyright 2022 Maria Sfiraiala (maria.sfiraiala@stud.acs.upb.ro)
-
Singleton Pattern
This pattern (or better called, anti-pattern) was used in order to simulate the presence of a global variable,
session
. Due to this value being required to globally maintain its value, in order forcurrentUser
andcurrenPage
to be easily updated from other methods, the choice of using a Singleton pattern was obvious.However, the
Singleton Pattern
has its disadvantages: Singleton makes it difficult to identify the instance in its calling class; its object becomes directly accessible without being passed through the constructors. As the code grows, it's more and more difficult to identify how different objects are related, therefore introducing ambiguities. -
Factory Pattern
This pattern was used in order to manage the creation of pages that inherit the abstract class
Page.java
. One of the main reason as to why we decided to use this pattern is that Factory provides abstraction between implementation and client classes through inheritance. Our code becomes more robust, less coupled and easy to extend, therefore coming closer to what an OOP project should strive be. -
Strategy Pattern
We used Strategy in order to improve the sorting mechanism. By dynamically applying each sorting method, without checking from what class it is coming from, as we wanted to just make the decision once and forget about it. Another reason is that Strategy permits decoupling the decision about which strategy to use from the code that needs to execute the strategy, therefore, the platform flow is just ✨ better ✨.
-
Facade Pattern
This one should be obvious as to why we used it. It allows the user (ergo, the teacher assistant reading this README) to see the nice, clean part of our code (the entry point to the application). Facade covers the complexity and lets the customer use our product without worrying about the internals.
src/
commands/
→ implementation ofon page
andchange page
commands + utilsCommands.java
→ utils commands include output related ones and deep copy methodsDatabase.java
→ database add and delete commandsRecommendation.java
→ recommendation for premium user algorithm
info/
→ classes that extend the information from inputMovie.java
Notification.java
User.java
input/
→ classes used for getting input, some of them will bes used as isActionInput.java
→ used as is, no need to add more infoContainsInput.java
CredentialsInput.java
→ used as is, no need to add more infoDataInput.java
→ aggregates info from all the other classes in this packageFiltersInput.java
→ used as is, no need to add more info; contains instances ofContainsInput
andSortInput
MovieInput.java
→ will be extended byMovie
SortInput.java
UserInput.java
→ will be extended byUser
pages/
→ classes used for building the hierarchyAuthenticated.java
Login.java
Logout.java
Movies.java
Page.java
→ abstract class, every other special page will extend itPageFactory.java
→ Factory design pattern used for creating pagesPageHierarchy.java
→ utility class, simply creates the particular hierarchy of our platformRegister.java
SeeDetails.java
Upgrades.java
platform/
FacadeSession.java
→ Facade design pattern used for easing user experienceSession.java
→ class that starts the session, refreshes it (after each test) and stores essential info (movies and users database, current user and page)
strategy/
SortByDuration.java
→ sorts movies based on duration; implementsSortStrategy
SortByRating.java
→ sorts movies based on rating; implementsSortStrategy
SortStrategy.java
→ interface used for Strategy design pattern when sorting based on multiple factors
The program starts by creating (or refreshing) the session. The current session will take care of creating the database used for movies and users, together with initializing each user with the input info + its visible movies (depending on the country).
It's the Session
that also sends commands to static methods like changePage
or onPage
.
Once the control is passed to these methods, the Session
instance will be updated only regarding the current user and page.
Inside the Commands
methods, we'll let each page take care of its own actions.
Each page will also change the current page and user, when needed.
Note: A key element in this process is the page hierarchy that was constructed at the start of the session, it stores the pages, that have info not only about next pages but also about the actions that can be performed on them.
The page takes care of itself by an inheritance mechanism got from its parent (the changePage
method) and by having its own methods, applied at the right time.