Question

I have a class, Thing, which has a number of variables. I also have a class, FileHandler, which records data to log files.

The FileHandler is specific to the instantiation of a Thing and needs to print several of the instance variables of Thing. So, Thing is imported into FileHandler.

There is another class, OtherThing, which also needs a Filehadler. Unfortunately, Thing imports OtherThing for reasons specific to the nature of Thing and OtherThing. This means that FileHandler imports Thing and Thing imports OtherThing which in turn imports FileHandler.

I can't seem to pull these apart. I will add more to this post depending on the comments. Is there an obvious reason that I cannot separate my classes here? It seems to be due to the fact that there is common data, that is needed by three classes.

Was it helpful?

Solution

Following this wording...

"All problems in computer science can be solved by another level of indirection... Except for the problem of too many layers of indirection." [David Wheeler]

...I would suggest to add an interface. Without knowing the exact code it's hard to decide. Maybe you try to introduce IThing or IFileHandler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top