How can I design a class named allergy

requirement: design a class named allergy that provides information about the allergy of a patient. e.g. who reported the allergy(patient/doctor/relative), different symptoms of the allergy that are detected, severity, method that returns when was that allergy detected in that patient.

I am thinking of something like this:

public abstract class Allergy{
    private String reporter;
    private String symptoms;
    private int timeReported;
    private int severity;

//Higher the number, higher the severity

    public Allergy(String reporter, String symptoms, int timeReported, int severity){
        this.reporter=reporter;
        this.symptoms=symptoms;
        this.timeReported=timeReported;
        this.severity=severity;
    }

    public void setReporter(String reporter){
        this.reporter=reporter;
    }

    public void setSymptoms(String symptoms){
        this.symptoms=symptoms;
    }

    public void setSeverity(int severity){
        this.severity=severity;
    }

    public void setTimeReported(int timeReported){
        this.timeReported=timeReported;
    }

    public String getReporter(){
        return reporter;
    }

    public String getSymptoms(){
        return symptoms;
    }

    public int getSeverity(){
        return severity;
    }

    public int getTimeReported(){
        return timeReported;
    }
}

Is this a good design of the class? Is there any way I can improve the design? Or does someone have a better implementation?

I have to be able to explain as many OOP concepts. Can I make use of any other OOP concept here apart from abstract, encapsulation and inheritance that I will be able to use having the current design in my mind?

Leave a Comment