samedi 11 janvier 2020

a different design pattern for this solution

I am having an interface that holds three different methods. And there are two class Car and Plane which will implement the Vehicle interface to get access to those methods. There are two questions that I have in my mind.

1. What type of design pattern satisfies the following implementation?

2. Is there any other design pattern to satisfy similar kinds of functionalities?

Though I have tried some blogs and questions I have found one answer regarding the second question which is using Anonymous Class but which leads to more garbage code. So is there any solution or answer to my questions?

public interface Vehicle {
    int set_num_of_wheels();
    int set_num_of_passengers();
    boolean has_gas();
}
public class Car implements Vehicle{

    @Override
    public int set_num_of_wheels() {
        return 0;
    }

    @Override
    public int set_num_of_passengers() {
        return 0;
    }

    @Override
    public boolean has_gas() {
        return true;
    }

}

public class Plane implements Vehicle{

    @Override
    public int set_num_of_wheels() {
        return 0;
    }

    @Override
    public int set_num_of_passengers() {
        return 0;
    }

    @Override
    public boolean has_gas() {
        return true;
    }

}

Aucun commentaire:

Enregistrer un commentaire