Static funtions API and Property based API
Reading time : Less than 15 minutes
For most of the advanced users, these two terms will be much familiar. So, this article is for new developers. Most of the today’s desktop programming toolkits are object oriented. Lets take an example of popular X-Window GUI toolkits like GTK+ or Qt, both are object oriented. GTK+ is written in C, and the object-orientation in GTK+ is achieved by using the GLib object system, whereas Qt is written in C++ and is purely object oriented. The main, advantage of object oriented design in widget toolkits is that, they can model entities like windows, widgets, or features etc as objects. By definition as objects should have three properties,
- Identity, which makes an object unique
- Attributes, which specifies the state of an object
- Methods, which defines the behaviour of an object
It is very easier for the toolkit developer to make an exact analogy with a GUI elements like a window or a widget in object oriented programming. Even though it makes the life of the toolkit developers job a bit happier, on the other side, application developers face a minute problem. I’m not sure if I could say it is a problem, but still there is something I would like to point out as an application developer, who extensively uses toolkits. A completely object oriented toolkit always provides a property based API, which means, to do something with an element inside it, we have to do the following steps.
- Create an object of that element
- Set required properties to that object to change its state like we do
- Call one of the methods to get the functionality from the object
It may look simpler to some new programmers since they play with pretty simple tasks most. When it gets a little bit complex, say if you are developing a complex application, you cannot spend that much time to do a simple task in between the actual coding. For example, if you are developing a big ERP system, you cannot always spend much time to show different kind of message boxes in between for different purposes. That will increase the number of lines of code in your application and you get messed up with the logic of the application as a whole.
One of the easy way to manage this is, to create a simple function which can take a number of parameters/arguments, call the required method and finally return a useful value to the developer. In case of a message box, it can take the message text, names of buttons to be shown and finally can return which button the user have clicked on. So, apparently we can tweak the three step process into a one step process, which is just a function call. But this has a scalability issue when the message boxes requires completely different kind of apparances in different occurrences - eventually we will keep on developing our custom function to handle all of the cases, which again causes problems. But, the developers life gets much more happier if the toolkit itself contains those kind of functions! Here comes the concept of Static Functions API. Most of the today’s toolkits has both of these APIs so that developers can use them appropriately according as the situation. A good example I’ve seen is : the Qt Message Box API itself. So that’s all, and I hope, when you look into documentations you will keep this post in mind to choose stuff a little more wisely.
//See you in the afterlife
//Subin Sebastian





