• 15 heures
  • Moyenne

Ce cours est visible gratuitement en ligne.

course.header.alt.is_video

course.header.alt.is_certifying

J'ai tout compris !

Mis à jour le 03/07/2020

Get some practice reorganizing an existing codebase using three-tier architecture and dependency injection

It's your turn

You’re a new developer at a small consulting company.  This company provides information about cost of living in cities around the world to international businesses. You've replaced another developer who has moved on to a new job. Previous developers mean existing code: instead of starting a project from scratch, you are inheriting an existing codebase, and picking up where the previous dev left off.

Your new company!
Your new company!

You are asked to add some new features to the code, but right off the bat, you realize that there are no unit tests whatsoever! You are a smart Java developer, and you know this will be a bit of a minefield! 💥 So, you want to start by adding some unit tests. But unfortunately, the architecture of the code does not allow it; all the logic is mixed together in the controller class. 😱

It’s not all bad news! The previous developer has left some good comments in the code that explain what is what.  You want to take this code and refactor it according to three-tier architecture, and wire components to each other using dependency injection. So, you scribble out a quick to-do checklist, which reads as follows:

  1. Move all the logic regarding initializing and searching the rental data into a repository class called RentRepository.

  2. Move the calculation logic regarding rent calculation in the target currency into a service class RentService.

  3. Move the logic to call the remote API, and get the conversion rate into a service called CurrencyService.

  4. Instead of creating  new  service and repository instances, create constructors and use dependency injection annotations to wire your components to each other.

  5. Organize classes into packages.

As it is a refactoring effort, the application should still work as it used to before changes.

You have access to the source code, which is a Spring Boot application, via this ZIP file. You'll need to download, unzip, and import it into your IDE. Now it’s time to put all that hard earned three-tier architecture, refactoring, and dependency injection knowledge to use and make life easier for you and those that follow in your footsteps! 💪

Check your work!

Check that the following elements are present:

  • All the logic regarding initializing and searching the rental data has been moved into a repository class called RentRepository.

  • The calculation logic regarding rent calculation has been moved to the target currency and into a service class RentService.

  • All the logic to call the remote API and get the conversion rate has been moved into a service called CurrencyService.

  • Constructors and dependency injection annotations have been used instead of creating  new  service and repository instances.

  • All classes are organized into packages.

  • The functionality of the original application has been maintained.

Exemple de certificat de réussite
Exemple de certificat de réussite