We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenge 4 - Colour buttons
#16
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. Angry

In the future I will always have to include the source code as "Code". Smile
[-] The following 1 user Likes Scout's post:
  • AbsoluteBeginner
Reply


Messages In This Thread
Challenge 4 - Colour buttons - by litdev - 09-04-2024, 06:06 PM
RE: Challenge 4 - Colour buttons - by jrmrhrb00 - 09-04-2024, 07:35 PM
RE: Challenge 4 - Colour buttons - by Scout - 09-04-2024, 09:23 PM
RE: Challenge 4 - Colour buttons - by litdev - 09-05-2024, 09:11 AM
RE: Challenge 4 - Colour buttons - by Scout - 09-05-2024, 11:16 AM
RE: Challenge 4 - Colour buttons - by WhTurner - 09-07-2024, 12:01 PM
RE: Challenge 4 - Colour buttons - by Scout - 09-07-2024, 08:12 PM
RE: Challenge 4 - Colour buttons - by jrmrhrb00 - 09-08-2024, 11:02 AM
RE: Challenge 4 - Colour buttons - by Scout - 09-08-2024, 08:45 PM
RE: Challenge 4 - Colour buttons - by z-s - 09-09-2024, 02:28 AM
RE: Challenge 4 - Colour buttons - by z-s - 09-09-2024, 04:07 AM
RE: Challenge 4 - Colour buttons - by litdev - 09-09-2024, 08:20 AM
RE: Challenge 4 - Colour buttons - by Scout - 09-09-2024, 09:26 AM
RE: Challenge 4 - Colour buttons - by z-s - 09-09-2024, 10:12 AM
RE: Challenge 4 - Colour buttons - by litdev - 09-09-2024, 11:16 AM

Forum Jump:


Users browsing this thread: 4 Guest(s)