Test Driven Development with JUnit 5. Part 4

4. Refactoring the flight-management application

  • We declare the class as abstract, making it the basis of the flight hierarchy #1.
  • We make the passengers list package-private, allowing it to be directly inherited by the subclasses in the same package #2.
  • We declare addPassenger and removePassenger as abstract methods, delegating their implementation to the subclasses #3.
  • We declare the EconomyFlight class extending the Flight abstract class #1 and create a constructor calling the constructor of the superclass #2.
  • We implement the addPassenger method according to the business logic: we simply add a passenger to an economy flight with no restrictions #3.
  • We implement the removePassenger method according to the business logic: a passenger can be removed from a flight only if the passenger is not a VIP #4.
  • We declare the BusinessFlight class extending the Flight abstract class #1 and create a constructor calling the constructor of the superclass #2.
  • We implement the addPassenger method according to the business logic: only a VIP passenger can be added to a business flight #3.
  • We implement the removePassenger method according to the business logic: a passenger cannot be removed from a business flight #4.

--

--

--

https://www.luxoft-training.com/

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

ViewModels under the hood..

C Programming — Introduction

EV charge station data: availability, price and more.

Coding Period 1: Week 2

Scaling: Making Doctolib Small Again

What is the Game of Life?

Decorators and Mixins in Lightning Web Components

Learning C++: Sorting Algorithms of the STL

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Luxoft Training

Luxoft Training

https://www.luxoft-training.com/

More from Medium

Singleton Design Pattern in java

Garbage Collection — Java Architecture

Deep dive into Pattern Matching for Java

Why we use Java at Jibit