Click here to Skip to main content
15,503,700 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
AnswerRe: Would it be possible to build megastructures like the Forerunners in <i>Halo</i>? Pin
jschell30-Dec-21 8:42
jschell30-Dec-21 8:42 
Questionquantum computing Pin
Calin Negru28-Dec-21 8:13
Calin Negru28-Dec-21 8:13 
AnswerRe: quantum computing Pin
Gerry Schmitz28-Dec-21 8:25
mveGerry Schmitz28-Dec-21 8:25 
GeneralRe: quantum computing Pin
Calin Negru2-Jan-22 3:48
Calin Negru2-Jan-22 3:48 
AnswerRe: quantum computing Pin
Member 155103601-Feb-22 2:41
Member 155103601-Feb-22 2:41 
QuestionRefactoring a Slow UI Pin
Kevin Marois21-Dec-21 10:01
professionalKevin Marois21-Dec-21 10:01 
AnswerRe: Refactoring a Slow UI Pin
englebart15-Feb-22 18:21
professionalenglebart15-Feb-22 18:21 
Question[Solved] Opinions on two code layout alternatives? Pin
RobertSF10-Dec-21 11:43
professionalRobertSF10-Dec-21 11:43 
I have an application that reads a directory's files, displays them in a grid, and offers a toolbar with buttons that invoke functions that apply to all the files in the grid.

In the following code, reduced to its essentials, when the user clicks the Trim button in the toolbar, toolTrim_Click executes, opening the form that collects the options for the Trim operation, and then invoking the method that trims the pages from the list of files. That method then invokes for each file the method that trims the pages from that particular file. The async part is just to keep the window draggable.
C#
//Main Form:
private async void toolTrim_Click(object sender, EventArgs e)
{
    var form = new TrimOptions();
    DialogResult result = form.ShowDialog();
    if (result == DialogResult.OK)
    {
        await Task.Run(() => filesList.TrimPages(form.trimFirst, form.trimLast, form.ifBlank));
    }
    form.Dispose();
}

//filesList Class:
public void TrimPages(bool trimFirst, bool trimLast, bool ifBlank)
{
    for (int entry = 0; entry < TotalPDFs; entry++)
    {
        FileEntry thisFile = list[entry];
        thisFile.Trim(trimFirst, trimLast, ifBlank);
    }
}

//thisFile Class:
public void Trim(bool front, bool back, bool ifBlank)
{
    // code
}
What would be the pros and cons of refactoring the above code like this? The difference is that we move opening the options form to the class that manages the list of files instead of keeping it in the main form class.
C#
//Main Form:
private async void toolTrim_Click(object sender, EventArgs e)
{
    await Task.Run(() => filesList.TrimPages());
}

//filesList Class:
public void TrimPages(bool trimFirst, bool trimLast, bool ifBlank)
{
    var form = new TrimOptions();
    DialogResult result = form.ShowDialog();
    if (result == DialogResult.OK)
	{
		for (int entry = 0; entry < TotalPDFs; entry++)
		{
			PDFEntry thisFile = list[entry];
		}
	}
}

//thisFile Class:
public void Trim(bool front, bool back, bool ifBlank)
{
    // code
}
It seems to me that the class that manages the list of files should be the class that collects the various operation options, but I don't know which is the best practice, or what the implications are of doing it the second way.

modified 2-Jan-22 19:11pm.

AnswerRe: Opinions on two code layout alternatives? Pin
Gerry Schmitz11-Dec-21 7:08
mveGerry Schmitz11-Dec-21 7:08 
GeneralRe: Opinions on two code layout alternatives? Pin
RobertSF11-Dec-21 8:09
professionalRobertSF11-Dec-21 8:09 
GeneralRe: Opinions on two code layout alternatives? Pin
Gerry Schmitz11-Dec-21 8:43
mveGerry Schmitz11-Dec-21 8:43 
GeneralRe: Opinions on two code layout alternatives? Pin
RobertSF11-Dec-21 12:44
professionalRobertSF11-Dec-21 12:44 
AnswerRe: Opinions on two code layout alternatives? Pin
englebart29-Dec-21 16:56
professionalenglebart29-Dec-21 16:56 
GeneralRe: Opinions on two code layout alternatives? Pin
RobertSF2-Jan-22 14:10
professionalRobertSF2-Jan-22 14:10 
QuestionDocumentation or modeling tool for a DB-application Pin
Member 1331165719-Nov-21 20:43
Member 1331165719-Nov-21 20:43 
AnswerRe: Documentation or modeling tool for a DB-application Pin
Gerry Schmitz1-Dec-21 19:29
mveGerry Schmitz1-Dec-21 19:29 
AnswerRe: Documentation or modeling tool for a DB-application Pin
Mycroft Holmes2-Dec-21 12:01
professionalMycroft Holmes2-Dec-21 12:01 
GeneralRe: Documentation or modeling tool for a DB-application Pin
Member 133116573-Dec-21 5:55
Member 133116573-Dec-21 5:55 
GeneralRe: Documentation or modeling tool for a DB-application Pin
Mycroft Holmes3-Dec-21 12:29
professionalMycroft Holmes3-Dec-21 12:29 
QuestionAsync design Pin
Mycroft Holmes10-Nov-21 12:31
professionalMycroft Holmes10-Nov-21 12:31 
AnswerRe: Async design Pin
Gerry Schmitz10-Nov-21 21:26
mveGerry Schmitz10-Nov-21 21:26 
AnswerRe: Async design Pin
Richard Deeming10-Nov-21 22:39
mveRichard Deeming10-Nov-21 22:39 
GeneralRe: Async design Pin
Mycroft Holmes11-Nov-21 13:29
professionalMycroft Holmes11-Nov-21 13:29 
AnswerRe: Async design Pin
Greg Utas11-Nov-21 3:13
mveGreg Utas11-Nov-21 3:13 
QuestionCommon Code Pin
Kevin Marois3-Nov-21 14:00
professionalKevin Marois3-Nov-21 14:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.