G
Guest
This must be a common GUI design issue - whether to treat the GUI object
which represents a thing as if it were the thing itself.
I'll put it in the form which I've come across recently...
I have a GUI which is a controller for an instrument, and I have a
UserControl which represents the instrument.
Imagine that the UserControl has a text box for the instrument frequency,
and a button to turn it off and on.
A couple of classes, apart from the GUI, access the instrument.
So the outline is... (making some simplifications)
class Instrument: UserControl
{
// public stuff, which is synchronised with the GUI
public double Frequency;
public bool isStarted;
public void Start();
// private implementation of the GUI
private TextBox frequencyControl();
... other GUI elements...
}
Instrument instrument;
class InputController
{
if (!instrument.isStarted)
{
instrument.Start();
instrument.Frequency = GetFrequencyFromExternalSource();
}
}
class OtherInstument
{
double myFrequency = (instrument.Frequency * 1.5);
}
}
The good thing about this is that it is simple. The problem is that every
class which depends on the Instrument, also depends on Windows.Forms. In
addition, because Instrument is actually quite large, and complex, the
complexity of the GUI is combined with the complexity of the the application
doman.
Should I break Instrument into two classes? ...
// The real instrument
Instrument
{
double Frequency;
bool isStarted;
void Start()
}
// The GUI
InstrumentControl: UserControl {...}
The GUI InstrumentControl, the InputController, and the OtherInstrument, all
access the more primitive Instument class.
My gut feeling is that I should do the separation, but in the real world
case I am dealing with, the Instrument actually has many properties and
methods, so making the two classes will see a lot of duplicated code, all for
the sake of an aesthetic improvement, with negligible real advantage. On the
other hand, I like my designs to represent "best practice".
TIA,
Javaman
which represents a thing as if it were the thing itself.
I'll put it in the form which I've come across recently...
I have a GUI which is a controller for an instrument, and I have a
UserControl which represents the instrument.
Imagine that the UserControl has a text box for the instrument frequency,
and a button to turn it off and on.
A couple of classes, apart from the GUI, access the instrument.
So the outline is... (making some simplifications)
class Instrument: UserControl
{
// public stuff, which is synchronised with the GUI
public double Frequency;
public bool isStarted;
public void Start();
// private implementation of the GUI
private TextBox frequencyControl();
... other GUI elements...
}
Instrument instrument;
class InputController
{
if (!instrument.isStarted)
{
instrument.Start();
instrument.Frequency = GetFrequencyFromExternalSource();
}
}
class OtherInstument
{
double myFrequency = (instrument.Frequency * 1.5);
}
}
The good thing about this is that it is simple. The problem is that every
class which depends on the Instrument, also depends on Windows.Forms. In
addition, because Instrument is actually quite large, and complex, the
complexity of the GUI is combined with the complexity of the the application
doman.
Should I break Instrument into two classes? ...
// The real instrument
Instrument
{
double Frequency;
bool isStarted;
void Start()
}
// The GUI
InstrumentControl: UserControl {...}
The GUI InstrumentControl, the InputController, and the OtherInstrument, all
access the more primitive Instument class.
My gut feeling is that I should do the separation, but in the real world
case I am dealing with, the Instrument actually has many properties and
methods, so making the two classes will see a lot of duplicated code, all for
the sake of an aesthetic improvement, with negligible real advantage. On the
other hand, I like my designs to represent "best practice".
TIA,
Javaman