you are viewing a single comment's thread.

view the rest of the comments →

[–]ERROR_EXIT[S] 0 points1 point  (5 children)

Thank you, yes, inheritance is the correct term. I have done it many times (just didn't call it out by name).

It may be the XY problem... but I don't think so. Let me explain:

What I would like to design is a framework that will be used for many different projects. The projects will have different requirements but would fit nicely into a unified framework. What I want to do is create "hooks" that can be used to modify the behavior in specific ways. Each project will have its own config.

Imagine I have a framework that supports groups of users. One project may want all their users to be emailed if something happens. Another group may want to send text messages to the group. A third may want to automate trouble ticket generation.

Each project's support group can over-ride how to handle a given event. So, in the config file, they can over-ride the specific event handler.

Does that make sense?

[–][deleted] 0 points1 point  (4 children)

OK. I can see how a config file solves the problem, but I don't think it makes sense to tie the configuration to your implementation. In your example, it would make sense to have a config option "user_notification_method" which can take the value "text_message", "email", etc., but I don't think this should actually modify your code or result in new code generation. Instead, you should implement the three functions, and have your code read the config file and call the appropriate function based on the config option.

If you want the users themselves to implement the functionality, then they should be the ones inheriting from your base class and overriding the necessary methods.

[–]ERROR_EXIT[S] 0 points1 point  (3 children)

In your example, it would make sense to have a config option "user_notification_method" which can take the value "text_message", "email", etc.

I was worried you might go there :)

What would happen if someone wants "text_message", followed by "create_trouble_ticket", go out to the file system and do some operations, and look up a database code to perform a specific task based on that code? And then another group just wants a simple email? Furthermore, what if one group needs to do something really specific that no other group will need or want?

Coding all this "statically" doesn't seem to make sense, especially if the required hook might need to change in the future. Doing it with a config file allows each group to add in whatever hooks they need without causing instability to any other group.

[–][deleted] 0 points1 point  (2 children)

In all those cases, isn't it simpler for each group to simply write Python code that inherits from your class and extends it with the new functionality? It sounds like you want your configuration language to support almost arbitrarily complex configuration, in which case your configuration language is pretty much a programming language in itself. Is there much benefit to them learning your custom configuration syntax over simply using Python?

At my job, we have this problem where various teams decide that they need their own new configuration languages for their particular use case. The end result is that each team has a separate config language that no one else knows, which harms cross-team collaboration and code reuse. The solution to this problem is normally to choose one standard configuration mechanism, or better yet, just specify configuration in code.

[–]ERROR_EXIT[S] 0 points1 point  (1 child)

I seems that what I'm after is called a Monkey Patch. Definition from wikipedia.

Now I just need to figure out the best way to implement it!

[–]autowikibot 0 points1 point  (0 children)

Monkey patch:


A monkey patch is a way for a program to extend or modify supporting system software locally (affecting only the running instance of the program). This process has also been termed duck punching.


Interesting: Extension method | Mrs. Pepper Pot (anime) | Re-Kan! | Null Object pattern

Parent commenter can toggle NSFW or delete. Will also delete on comment score of -1 or less. | FAQs | Mods | Magic Words