mardi 30 juillet 2019

Design pattern for Cab service

I am trying to understand design pattern and thought of implementing Abstract factory pattern to see how cab service like ola, uber could be designed.

I started with something of class segregation like below, but got stuck there after.

/* Ola has car type as Auto, micro, mini, prime.
 * Later add share car type. 
 * 
 * Add cars to the car type
 * */

enum CarType{
    MINI, MICRO, AUTO, PRIME;
}

public class OlaImplementationAbstract {

    public static void main (String[] ags) {

    }
}

class carFactory{

}
abstract class Car {

    public double fare(double distTravelled) {
        return distTravelled;
    }
}

class Mini extends Car {

    public double fare(double distTravelled) {
        return 9 * distTravelled;

    }
}

class Micro extends Car {

    public double fare(double distTravelled) {
        return 8 * distTravelled;

    }
}

class Auto extends Car {

    public double fare(double distTravelled) {
        return 7 * distTravelled;

    }
}

class Prime extends Car {

    public double fare(double distTravelled) {
        return 10 * distTravelled;

    }
}

Could not understand how to proceed further. I just wanted to understand if I got to design such a thing, how to go about it.

Aucun commentaire:

Enregistrer un commentaire