A Pop-Up Story
This is a tale of what i did at work today. It was lousy in a few ways but educating in many others (its all about perspective). Well, i was doing a lot of code refactoring today and it was truly, and no jokes here, truly a good leaning experience. The theme of today's lesson was simple, Encapsulation. In more elaborate terms, i learnt that service calls should not be made from pop ups. Why? Well, no one has given me any clear reason so far. But somehow it makes sense. A pop up is something very intermediate, right? Its primarily used for peripheral functions. All the actions of uploading data, giving out warning and status messages figures in pop ups. So why should you be making service calls from it? Apart from that, there is another reason why you should not be doing something like that: a pop up is essentially a control as well. Any control you ever make has to be under all circumstances independent of anything else.
If there is anything that needs to be passed on or from the control, define and use public properties or information hooks off the control or in this case a pop up. This allows you to create controls which can be used in more than one place. A lot of UI developers ask what that perfect design is, and i answer in terms of re-usability of that control or UI element. Today i learnt the nuances behind making reusable controls. And there is no great hard work or intelligence involved what so ever. It is just a matter of being deliberate and particular about a few simple rules:
like a class, exposing a few functions and methods. It should only give just about enough access for the controller or user of the control to make it do what it is supposed to. How it does it and how it manages its own configuration should be its own headache. That is how good independent code with the least amount of dependencies can be written. There is nothing more destructive to a coder than to write code which is dependent with its environment. Any and all code and solutions should and have to be as generic and independent as possible. That is how you are able to replace chunks of code easily in case something goes wrong. It also gives you the independence to separate the code out and, develop and test it independently.
I learnt it the hard way. I hope you pick it sooner. Cheers!
- i will not use any UI element of a control directly.
- i will not pass or extract any information from any UI element inside that UI control directly.
- if i have to set or get information or make configuration changes, i will do so via publicly defined properties which i will use as my birth right. ;)
- and i will set all my UI elements as private so that i never get to use them even if my evil mind tries to do otherwise. ;)