Hi z-s
thanks for the github-link of SmallBasic.
I didn't know the source code was public!?
Below are a few interesting lines
internal sealed class ControlsLibrary : IControlsLibrary
{
private readonly NamedCounter counter = new NamedCounter();
private readonly Dictionary<string, BaseControl> controls = new Dictionary<string, BaseControl>();
public string AddButton(string caption, decimal left, decimal top)
{
string name = this.counter.GetNext("Button");
this.controls.Add(name, new ButtonControl(name, caption, left, top, width: 80, height: 30));
return name;
}
public string AddMultiLineTextBox(decimal left, decimal top)
{
string name = this.counter.GetNext("TextBox");
this.controls.Add(name, new MultilineTextBoxControl(name, left, top, width: 200, height: 50));
return name;
}
public string AddTextBox(decimal left, decimal top)
{
string name = this.counter.GetNext("TextBox");
this.controls.Add(name, new TextBoxControl(name, left, top, width: 200, height: 20));
return name;
}
The names of the controls for the dictionary entry are assigned here.
But what if, as part of the program optimization, the name of MultiLineTextbox is changed from "TextBox" to "MultiTextbox"?
Or if a common counter is used instead of a separate counter for each name or the formatting is changed?
How the control library manages its dictionary entries is its sole responsibility and the application should only work with the results returned via a defined interface ("return name;").
It is the principle of object-oriented programming with encapsulation of classes that you should not know what is going on within the class.
I have not yet seen an official example in which the application works directly with the internal names, but only with the contents of the variables.
@litdev
In my previous post the indices of arrays clash with the formatting of the post.
I can't fix it.
In the future I will always have to include the source code as "Code".
thanks for the github-link of SmallBasic.
I didn't know the source code was public!?
Below are a few interesting lines
internal sealed class ControlsLibrary : IControlsLibrary
{
private readonly NamedCounter counter = new NamedCounter();
private readonly Dictionary<string, BaseControl> controls = new Dictionary<string, BaseControl>();
public string AddButton(string caption, decimal left, decimal top)
{
string name = this.counter.GetNext("Button");
this.controls.Add(name, new ButtonControl(name, caption, left, top, width: 80, height: 30));
return name;
}
public string AddMultiLineTextBox(decimal left, decimal top)
{
string name = this.counter.GetNext("TextBox");
this.controls.Add(name, new MultilineTextBoxControl(name, left, top, width: 200, height: 50));
return name;
}
public string AddTextBox(decimal left, decimal top)
{
string name = this.counter.GetNext("TextBox");
this.controls.Add(name, new TextBoxControl(name, left, top, width: 200, height: 20));
return name;
}
The names of the controls for the dictionary entry are assigned here.
But what if, as part of the program optimization, the name of MultiLineTextbox is changed from "TextBox" to "MultiTextbox"?
Or if a common counter is used instead of a separate counter for each name or the formatting is changed?
How the control library manages its dictionary entries is its sole responsibility and the application should only work with the results returned via a defined interface ("return name;").
It is the principle of object-oriented programming with encapsulation of classes that you should not know what is going on within the class.
I have not yet seen an official example in which the application works directly with the internal names, but only with the contents of the variables.
@litdev
In my previous post the indices of arrays clash with the formatting of the post.
I can't fix it.
In the future I will always have to include the source code as "Code".