0

This is mostly a program design question.

I have multiple identical instrument housings each of which contains four identical instruments that I can communicate with remotely. I want to make an instrument housing class that contains: methods to communicate with each housing, methods to do housing-specific operations, and the housing attributes (addresses) necessary to use those methods with them.

I additionally would like to make subclasses for the instruments themselves. These subclasses would have methods to do instrument-specific operations that call the superclass' methods and attributes to communicate through the housing.

The problem with this design is that each housing would ultimately have five instances: one for its operations and one for each of its four instruments.

Is it possible to create an instance of the housing class and then have subclasses inherit from the housing instance? Or am I thinking about this design in the wrong way (I'm relatively new to python)?

mugwump
  • 436
  • 1
  • 4
  • 10

2 Answers2

1

I may have misunderstood the question, but from what I understand, a housing has four (or some number of) instruments inside it. You would then want a class Housing and a class Instrument. A housing holds a list of instruments while each instrument is created with a reference to its housing. If an instrument has to do something special, you can inherit from Instrument and likewise for housings.

Mathias Bak
  • 4,687
  • 4
  • 32
  • 42
1

I found what I needed here:

https://stackoverflow.com/a/1081925/8217247

By using an instance of the Housing class as an argument when instantiating an Instrument and redefining __getattr__ its possible to have the Instrument children dynamically pull in the attributes of their instance Housing.

mugwump
  • 436
  • 1
  • 4
  • 10