Refactoring object of large set of properties
I have a class that looks like: class Vehicle: coordinates: GeoCoordinates speed: float rpm: float egt: float // 100+ other parameters A repertoire of concrete classes that use various parameters from Vehicle to execute their work: class BaseMetric: def value(self): pass class TelemetryMetric_1(BaseMetric): def __init__(vehicle: Vehicle) pass def value(self): // do work with vehicle class TelemetryMetric_2(BaseMetric): def __init__(vehicle: Vehicle) pass def value(self): // do work with vehicle class TelemetryMetric_N(BaseMetric): def __init__(vehicle: Vehicle) pass def value(self): // do work with vehicle So in this case I need to be able to pass in some object that can be used by the metrics to perform their work. However, I'm trying to refactor Vehicle so it's more than just a bag of properties. I need to be able to update Vehicle with an Update() method and track its previous state. How should I go about refactoring this so Vehicle is more than just a bag of 100+ properties that keeps growing. Some ideas I've come up with: A dictionary Logically group some of the parameters (results in a train-wreck of vehicle.engine.left.rpm.etc.etc) Leave vehicle as a bag of properties Modify the construction of each metric to take in something besides a vehicle
I have a class that looks like:
class Vehicle:
coordinates: GeoCoordinates
speed: float
rpm: float
egt: float
// 100+ other parameters
A repertoire of concrete classes that use various parameters from Vehicle to execute their work:
class BaseMetric:
def value(self):
pass
class TelemetryMetric_1(BaseMetric):
def __init__(vehicle: Vehicle)
pass
def value(self):
// do work with vehicle
class TelemetryMetric_2(BaseMetric):
def __init__(vehicle: Vehicle)
pass
def value(self):
// do work with vehicle
class TelemetryMetric_N(BaseMetric):
def __init__(vehicle: Vehicle)
pass
def value(self):
// do work with vehicle
So in this case I need to be able to pass in some object that can be used by the metrics to perform their work. However, I'm trying to refactor Vehicle so it's more than just a bag of properties. I need to be able to update Vehicle with an Update() method and track its previous state.
How should I go about refactoring this so Vehicle is more than just a bag of 100+ properties that keeps growing.
Some ideas I've come up with:
- A dictionary
- Logically group some of the parameters (results in a train-wreck of vehicle.engine.left.rpm.etc.etc)
- Leave vehicle as a bag of properties
- Modify the construction of each metric to take in something besides a vehicle