Mahoolya / hotels

0 stars 0 forks source link

Implement design patterns #38

Open Mahoolya opened 1 year ago

Mahoolya commented 1 year ago

Singleton pattern By default beans have singleton scope. So, creating HotelService (from the app) and using annotation @RequriedArgsConstructor(= @Autowired by field) we don't create two objects, only one, as in Singleton Pattern documentation. To change bean scope from singleton to prototype we can use @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) annotation => we will get two different objects.

Mahoolya commented 1 year ago

Dependency injection or inversion of control (IOC) This pattern is connected with bean injection. So we have Controller class, where we use some service. Service uses some repository. We add before beans @Autowired annotation and Spring injects all necessary beans.

Mahoolya commented 1 year ago

Model View Controller Pattern The goal of this pattern is to separate program into 3 layers: