mercredi 21 mars 2018

Using wrapper around a generic object, instead of specific objects

I have a design question im not too sure on. Say i have this "policy" sort of like a someone have car insurance or something.

There are tons of different kinds of policies that pop up all the time, so like earthquake, or trucking, or like drone, etc. I want this to be generic so they all sort of fit into this object. I was thinking of storing most of the details in a string hashmap.

public class Policy
{
    static final long serialVersionUID = 20130901L;

    private String policynumber;
    private int policyId;
    private String pendingDocType;
    private int transactionTypeId;
    private List<Integer> lobs;
    private List<Integer> markets;
    private Insured insured;
    private Agent agent;
    private Map<String, Location> locations;
    private Map<String, String> details;
}

Then for each different type, i create a wrapper class that extends policy with methods for accessing fields according the the type that it is. So if its a drone, i would have methods like

getAnnualFlightDistance()
{
    return details.get("flightdistance");
}
getAnnualPremium()
{ 
    // Some method to calculate the current money spent on policy
}

But just have helper methods around the main Policy class.

I would make them member variables for each field attached to it, but they're always changing variables a new things being added, i thought having just like a bin for the terms would allow for a constant evolving object.

Aucun commentaire:

Enregistrer un commentaire