473,789 Members | 2,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A GUI design issue

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 frequencyContro l();
... other GUI elements...
}

Instrument instrument;

class InputController
{
if (!instrument.is Started)
{
instrument.Star t();
instrument.Freq uency = GetFrequencyFro mExternalSource ();
}
}

class OtherInstument
{
double myFrequency = (instrument.Fre quency * 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
InstrumentContr ol: UserControl {...}

The GUI InstrumentContr ol, 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

Nov 17 '05 #1
6 1664
I understand your concern that GUI elements are getting up tied with
classes. But if really the class has to aggregate the GUI elements
thats fine. I mean if class is depenedent on UI element you have to use
it. If you are predicting forthe change from windows forms to web form
or viceversa you have to keep them seperate. In tier technology when we
say UI element should be independent of UI we mean that if we want to
remove windows forms and plug in web forms its should be done with
minimal changes. If you think you have to cater to windows as well as
webforms UI elements the seperattion is worth doing it.... or else will
just increase the complexity of project
-------
Regards ,
C#, VB.NET , SQL SERVER , UML , DESIGN Patterns Interview question book
http://www.geocities.com/dotnetinterviews/
My Interview Blog
http://spaces.msn.com/members/dotnetinterviews/

Nov 17 '05 #2
Will you be deploying your control via the .NET Compact Framework
or even an ASP.NET environment? If your control works well
in Windows, you can bet they'll ask for flavors in other environments
in the near future.

If it were me, I'd keep as much of it that isn't dependent on
one environment or the other in separate classes. I wouldn't
mind repetitive code closer to the actual UI code but I'd
do everything I could to shove as much of it as possible
into the shared classes.

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Javaman59" <Ja*******@disc ussions.microso ft.com> wrote in message
news:34******** *************** ***********@mic rosoft.com...
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 frequencyContro l();
... other GUI elements...
}

Instrument instrument;

class InputController
{
if (!instrument.is Started)
{
instrument.Star t();
instrument.Freq uency = GetFrequencyFro mExternalSource ();
}
}

class OtherInstument
{
double myFrequency = (instrument.Fre quency * 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
InstrumentContr ol: UserControl {...}

The GUI InstrumentContr ol, 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

Nov 17 '05 #3
Thankyou guys, both replies are very helpful. I had not thought of the issue
of web deployment, and I can say that in this case the control is part of a
much larger, and complex GUI which will not be deployed as a web form,
however there is some chance that the GUI could be required to *remotely*
control the instrument, in which case the Instrument object would be on a
separate platform to the GUI, or perhaps multiple GUI's. In the light of your
overall comments, I think that consideration is enough to justify making the
separate class.

Thankyou both for taking the time to share your insights.

Shiv, I liked your summary...

If you think you have to cater to windows as well as
webforms UI elements the seperattion is worth doing it.... or else will
just increase the complexity of project

and Robbie, your opinion...

I'd do everything I could to shove as much of it as possible into the shared
classes.

Although you are offering different recommendations (we are talking here of
the non-web case), your opinions and experience sum up the issue.

Javaman
Nov 17 '05 #4

Javaman59 wrote:
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 frequencyContro l();
... other GUI elements...
}

Instrument instrument;

class InputController
{
if (!instrument.is Started)
{
instrument.Star t();
instrument.Freq uency = GetFrequencyFro mExternalSource ();
}
}

class OtherInstument
{
double myFrequency = (instrument.Fre quency * 1.5);
}
}

The good thing about this is that it is simple.
Not for long.
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? ...
Definitely. If you don't it will quickly become extremely difficult to
maintain. I like to keep the GUI layer as thin as possible, so that
control event handlers merely forward the information to a model class,
and control appearance is updated only in response to the model
changing:

class DomainModel
{
public int SomeProperty { get { ... } set { ...; OnChange(); } }
public bool Frobbable { get { ... } }
public void Frob() { ...; OnChange(); }
public event EventHandler Changed;

private void OnChange()
{ if (Changed != null) Changed(this, EventArgs.Empty ); }
...
}

class DomainModelGui
{
public DomainModelGui( DomainModel model)
{
...
this.model = model;
model.Changed += model_Changed;
}

public void model_Changed(o bject sender, EventArgs unused)
{
somePropertyTex tBox.Text = model.SomePrope rty.ToString();
frobButton.Enab led = model.Frobbable ;
...
}

private void frobButton_Clic k
{
model.Frob();
}
...
}

Notice that none of the control event handlers have to worry about
changing the state of other controls. Every time the model changes,
the appearance of every control is refreshed.

// The real instrument
Instrument
{
double Frequency;
bool isStarted;
void Start()
}

// The GUI
InstrumentContr ol: UserControl {...}

The GUI InstrumentContr ol, 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


There should not be any duplicated code. One class implements the
domain logic, and the other maps the domain object to GUI controls.
Additionally, by separating the domain logic from the GUI, you
automated testing of the domain logic.

Nov 17 '05 #5
A GUI is just that: an interface. An interface is something that links one
thing with another thing. In this case, a user with a process. The process
may be exposed through any number of interfaces, including other user
interfaces, and other processes, via an API. Perhaps you're thinking, no,
that isn't going to happen in this case. Well, life is long, and many times
I've been surprised at how something I've written needs to be re-purposed.

Therefore, while the user interface should know how to "talk to" the
process, it should never participate in the process.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Javaman59" <Ja*******@disc ussions.microso ft.com> wrote in message
news:34******** *************** ***********@mic rosoft.com...
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 frequencyContro l();
... other GUI elements...
}

Instrument instrument;

class InputController
{
if (!instrument.is Started)
{
instrument.Star t();
instrument.Freq uency = GetFrequencyFro mExternalSource ();
}
}

class OtherInstument
{
double myFrequency = (instrument.Fre quency * 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
InstrumentContr ol: UserControl {...}

The GUI InstrumentContr ol, 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

Nov 17 '05 #6
And thankyou to the two Kevins. I'm really glad that I asked this question,
as the responses have been first rate, and really helped me get to grips with
this problem.
Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
6406
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but something I'll need in this case is some experience-based set of rules about how to use python in this context. For example... is defining readonly attributes in classes worth the hassle ? Does duck-typing scale well in complex
2
3576
by: Kymert persson | last post by:
Hi. I was wondering if there are any more C++ books along the lines of "Large scale C++ software design" by Lakos, J. I.e. concerning larger design issues in close relation to C++. I have made a fairly thorough literature search, but i haven't found anything fitting this criteria. In general there seems to be a huge amount concerning the C++ language as such and more "narrow" design issues, e.g. along the lines of Meyers Effective-
10
1924
by: eMKa | last post by:
Hi Code guru's I have created a user control which has access, and thus makes use of a shared singleton class like: Dim MyAppSettings As DLAppSettings = DLAppSettings.GetAppSettings This singleton class has amongst other stuff the following line of code in it: Private m_DL_DBPath As String = System.Configuration.ConfigurationSettings.AppSettings("DMDatabasePath") As you guess, it must read a string containing the path. Based on this...
2
1311
by: John Holmes | last post by:
This, I fear, is related to the fact that Visual Studio.NET reformats the HTML when going into design mode and then back out. I have an object tag that is using an object provided by a 3rd party vendor to use their signature pad. I set the <PARAM .. > tags and if I need to go into design mode it gets rid of the <PARAM> tags that I put in and puts every possible PARAM tag in with settings it gets from somewhere. This is very annoying. I...
1
1891
by: keliie | last post by:
I have a relatively simple (I assume) issue which I am at a complete loss to address. My issues is: I want to populate fields in my tables with summary data from the same table. Let me explain: tblItemDetails (contains data on food products purchased) Item_Description_ID (key, source link to tblMenuItemRecipe) Item_Unit_of_Measure Item_Location Item_Type Item_Category
0
2512
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that don't work nearly as well as they should, even for analysts and power users. The reason they haven't reached the masses is because most of the tools are so difficult to use and reveal so little
0
3698
by: Paul Hadfield | last post by:
I'm looking for thoughts on the "correct" design for this problem (DotNet 2.0 - in winforms, but that's not so important). I've got two combo boxes (combo1 and combo2), both are populating via database calls (using a separate DB handler class). "combo1" contains a list of countries and is fairly static, it can be added to but no other external events cause a change in its population. "combo2" however is populated with a list of options...
8
1873
by: obrianpatrick | last post by:
Hi, I am relatively new to object oriented programming and design. I am developing an application in VS 2005. I am having the following design problem: I have two interfaces X and Y. Y is derived from X as the following: __interface X {
5
1740
by: pgrazaitis | last post by:
I cant seem to get my head wrapped around this issue, I have myself so twisted now there maybe no issue! Ok so I designed a class X that has a few members, and for arguments sake one of the members Y is the location of a file to be read. The original design assumes that this class will be instantiated and each instance will happily mange its own members. (ie One file location per instance...no thread-safety). Now another class A...
4
2468
by: Ken Fine | last post by:
I've been living with a frustrating issue with VS.NET for some months now and I need to figure out what the problem is. Hopefully someone has run into the same issue and can suggest a fix. I suspect some permissions problem. I'm running VS.NET 2008 in Vista. Symptoms and observations: * ASP.NET's native ImageMap and Image controls work just fine and provide a design-time preview of images that are referenced via the ImageUrl property *...
0
9661
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10403
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10193
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7524
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6755
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5414
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5546
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4087
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.