mercredi 15 février 2017

Combining two large classes that share a list of objects of another class?

I currently have something like the following:

# Both classes maintain a list of these
class Cluster:
    def __init__(self):
        #some attributes gathered from SERVICE_A_reporter
        #some attributes gathered from SERVICE_B_reporter

#this does a few tasks relating to SERVICE A to build up a list of clusters 
class SERVICE_A_reporter:
    def __init__(self):
        self.clusters = []

#this does a few tasks relating to SERVICE B to build up a list of clusters
class SERVICE_B_reporter:
    def __init__(self):
        self.clusters = []

So each reporter class maintains its own list of clusters. I think it would be better to combine these into one class but I am not sure what would be the best way to do it

Similarities between SERVICE_A_reporter and SERVICE_B_reporter:

  • Both use similar code to build up an inital list of clusters
  • Both use similar code at the end when they produce a report and send metrics to our internal graphite server.

Differences between SERVICE_A_reporter and SERVICE_B_reporter:

  • They then get a new list of clusters in a different way for each and cross reference them with the initial list.
  • They each measure different things about the clusters.

I have many options to do this, but if I want to do it right, what is the best way? Thanks :)

Aucun commentaire:

Enregistrer un commentaire