Following the article Programmers Are People Too by Ken Arnold, I have been trying to implement the progressive disclosure pattern for an API.
Basically, the idea mentioned in the text is to break the API into categories and only present the user with what he or she needs. The rest is hidden, reducing complexity for someone using the API. In the text, he presents his idea with the JButton class and its 100+ methods:
[...] we could use progressive disclosure to help reduce the complexity of that JButton class: put the expert stuff in an object returned by a getExpertKnobs() method, and the graphics subsystem hooks in an object returned by a getIntegrationHooks() method, and you would be left with a button API that had just a handful of methods—the basic methods we all need.
I have been trying to implement a minimal example of this using C++. So far, I have not gotten acceptable results. What I want is this behavior and simplicity:
First, the class containing only the basic and widely spread methods:
struct Base
{
Base()
{
// Initialize attributes (possibly many)
}
void simpleMethod()
{
// Do something simple...
}
ExtBase ext()
{
// Access to advanced features;
// this is the tricky part for me...
}
private:
// Attributes...
};
Then, the class containing the advanced/expert stuff:
struct ExtBase
{
ExtBase()
{
// Not sure of what goes here...
}
void advancedMethod()
{
// Do something complicated...
}
};
Ideally, this "API" could be used simply like this by the user:
int main()
{
Base aBase;
aBase.simpleMethod(); // OK
aBase.advancedMethod(); // Fails. Not available by default.
aBase.ext().simpleMethod(); // Possibly OK, not sure...
aBase.ext().advancedMethod(); // OK
return 0;
}
I have been looking around the web to find examples of this, but so far, nothing really interesting came up. I did find an example in Java from this library but I was not able to replicate it in C++.
Does anyone have any idea on how this could be done?