0

I was asked this question in interview, but could not find answer anywhere:

Lets say a application has feature which will unlock to different feature to diff customer lets say addition, deletion, edit allowed only for user1 user2 and user3, so I have already written code for all features and created exe, but when some customer pay extra I activate out of addition edit for example feature like happens in games, I found is impossible to do by config file ? I suggested writing switch case in code and change userlevel in config file. But I am not sure. Is there any way to do above problem using OOPS and config file.

1

4 Answers 4

2

There are many solutions to the general problem you present. I will not get into disadvantages or advantages, just enumerate a few ways for you to explore further, and in no way I expect to be exhaustive

Input options (to define which options to enable/disable):

a) Config file

a.1 - add toggle variables (many feature variables, each true/false)

a.2 - add feature string list (e.g. "features"="feature1,feature2,feature4" implies feature 3 is disabled)

b) Database table

b.1 - single table with a row per feature

b.2 - single row with a list of features

b.3 - multiple tables, for example relating users vs. features

c) Registry (generally similar to config solutions, but can be used as a database through subkeys)

d) Proprietary file (similar to config but you define a specific file structure)

e) Web service (program connects to a service to get configuration, then similar to config file). Particularly common for mobile apps

e.1 - receives JSON

e.2 - receives XML

e.3 - proprietary format

Processing options (to define how to execute the enabled/disabled ):

a) Set boolean variables, use if on specific code paths

b) Switch statement (your solution)

c) Strategy pattern

d) Apply IoC pattern where you load a specific processor depending on the configuration

1

You certainly can do it by having settings in the config file. Technically, that is possible.

The biggest drawback is that everybody can edit that file very easily. That is the whole point of a config file.

Assuming different customers pay different amounts of money to get those features, you may want more secure means of granting access to features. There are many ways to do this, the config is not one of them.

1
  • To build on nvoights answer, most likely you are going to give them a license. As part of that license it will include the features that are enabled of it. You build mechanisms to secure and enable the license to be tamper resistant/proof. If the customer wants more features, you issue then a second license with those feature or update there current license.
    – Jon Raynor
    May 3, 2017 at 15:44
1

There are two questions here.

First is implementation of features that can be toggled on/off. This is just way to complex of a topic and highly depends on your application, it's design and feature that needs to be toggled.

Second is allowing feature for only specific customers. In this case, you are looking for some kind of licensing scheme. There are (paid) services/libraries that provide "hard to crack" licensing. In which case your application consults this service/library if current customer has needed license. But is really a problem for applications that customer runs himself. If your application is web service you run on your own servers, then it becomes as trivial as querying your customer DB and checking if he has the feature bough.

1

The common solution is to design and implement some licensing library, probably complete with a licensing server, machine-specific license keys, etc. The keys do contain encrypted information about the customer, the machine, and the feature levels purchased for this key.

The proper solution is to purchase a licensing solution that does the above (with significantly less bugs) and integrate it.

The quick fix until either of the above are implemented is to indeed use a simple undocumented entry in a local config file (where "file" is a metaphor for any kind of storage), possibly obscured with some form of trivial obfuscation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.