473,394 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Proper separation of interface and logic?

I am new to C#, and have written some code to update a textbox control
on a form with the output from an external script. However, I am not
sure if I have properly separated the user interface from the script
processing logic. Would somebody please look at the code below and
let me know if there is anything I should change? (I have omitted
implementation details):
================================================== =
[ScriptProcessor.cs]
class ScriptProcessor {
public delegate void UpdateTextCallback(string text);
Process p;
Thread t;
public ScriptProcessor(RichTextBox output,string script) {
p = new Process();
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo .... //(set up Process object)
}
public void Run() {
t = new Thread(new
ThreadStart(StartProcessAndUpdateRichTextBox));
t.Start();
}
private void StartProcessAndUpdateRichTextBox() {
p.Start();
while ((string stdout = p.StandardOutput.ReadLine()) !=
null) {
richText.Invoke(new
UpdateTextCallback(this.UpdateRichTextBoxStdout), stdout);
}
p.WaitForExit();
}
private void UpdateRichTextBoxStdout(string text) {
AppendText(richText, Color.Black, text + "\n");
}
private void AppendText(RichTextBox r, Color c, string text) {
... //print to richtextbox
}
}
[Form1.cs]
....
ScriptProcessor sp;
public Form1() {
InitializeComponent();
sp = new ScriptProcessor(this.richTextBox1, "path-to-
script");
}
private void button1_Click(object sender, EventArgs e) {
sp.Run();
}
================================================== =
Among things I am unsure of, are the location of the
UpdateRichTextBox...() function (shouldn't it be in the Form's
code??), and the fact that RichTextBox has to be hard-coded into the
ScriptProcessor implementation (maybe I should use a generic?).

How should I change this?

Thanks!!
Robert Waters
-www.computerator.com
Oct 13 '08 #1
2 1437
On Oct 13, 1:49 pm, "robert.waters" <robert.wat...@gmail.comwrote:
I am new to C#, and have written some code to update a textbox control
on a form with the output from an external script. However, I am not
sure if I have properly separated the user interface from the script
processing logic. Would somebody please look at the code below and
let me know if there is anything I should change? (I have omitted
implementation details):

Take a look at MVP design pattern.
Oct 13 '08 #2
On Oct 13, 2:01*pm, "Ignacio Machin ( .NET/ C# MVP )"
<ignacio.mac...@gmail.comwrote:
On Oct 13, 1:49 pm, "robert.waters" <robert.wat...@gmail.comwrote:
I am new to C#, and have written some code to update a textbox control
on a form with the output from an external script. *However, I am not
sure if I have properly separated the user interface from the script
processing logic. *Would somebody please look at the code below and
let me know if there is anything I should change? *(I have omitted
implementation details):

Take a look at MVP design pattern.
Thank you, that is exactly what I am trying to accomplish.
Do you have any idea what part of the code I listed could be
refactored out of the layer in which it currently exists?
I am trying to teach myself by example, and some hints in this matter
would be enormously helpful.
Oct 13 '08 #3

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

Similar topics

8
by: Eric Veltman | last post by:
Hello everyone, I've posted this question before, but got no answer, so I'll try to reformulate the question, maybe it helps :-) By the way, this is not intended as the start of an ASP.NET...
13
by: Droolboy | last post by:
I'm trying to build a fairly small (max. 10 different pages) site using php, and it's becoming obvious that I need some kind of model view separation. Having done a few searches, I've come...
20
by: Griff | last post by:
Hi there I'm after some suggestions as to how one might best separate form and content in a normal run-of-the-mill web application. I'm sure whole bookshelves have been written on this, but I...
3
by: Erik Harris | last post by:
I apologize if this is a stupid question - I'm relatively new to OOP. I have a property that must exist in a class in order to be used by another class. The property, however, does not change with...
7
by: Rob R. Ainscough | last post by:
I understand and implement the concept (as best I can), BUT what I would like to know -- how is it possible to completely remove the UI from business logic? "UI references business logic, but...
14
by: ToddLMorgan | last post by:
Summary: How should multiple (related) projects be arranged (structured) and configured so that the following is possible: o Sharing common code (one of the projects would be a "common" project...
11
by: giddy | last post by:
hi , ok , i have a programming background but i'm new to C# . i'm also self taught so : i have a datagridview that should act differently depending on which user has signed in now is it...
10
by: Frank van Wensveen | last post by:
Friend, coders, fellow wage slaves, lend my your ears. I believe that in a perfect world the design of a website (or feature on a website) should be totally separated from its design and the data...
9
by: msbs1984 | last post by:
Difference Between Interface and Abstract Class?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.