Files
java-design-patterns/single-table-inheritance/src/main/java/com/iluwatar/entity/Train.java
T
Ved Asole b2c7410c03 feat: #1316 Single Table Inheritance pattern implemented (#2632)
* implemented single table inheritance

* added the Java documentation for the pattern

* updated code files as per the standards

* added the puml and png diagram for the file

* added README.md

* #1316 Single Table Inheritance pattern implemented

* resolved the Checkstyle violations

* removed the tests due to build failure

* updated the code as per review

* resolved Checkstyle violations
2024-02-25 14:20:13 +02:00

39 lines
943 B
Java

package com.iluwatar.entity;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* A class that extends the PassengerVehicle class
* and provides the concrete inheritance implementation of the Car.
*
* @see PassengerVehicle PassengerVehicle
* @see Vehicle Vehicle
*/
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Entity
@DiscriminatorValue(value = "TRAIN")
public class Train extends PassengerVehicle {
private int noOfCarriages;
public Train(String manufacturer, String model, int noOfPassengers, int noOfCarriages) {
super(manufacturer, model, noOfPassengers);
this.noOfCarriages = noOfCarriages;
}
// Overridden the toString method to specify the Vehicle object
@Override
public String toString() {
return "Train{"
+ super.toString()
+ '}';
}
}