Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6807131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:47:40+00:00 2026-05-26T19:47:40+00:00

I implemented a plugable framework like below. It works but I’m confused about the

  • 0

I implemented a plugable framework like below.

It works but I’m confused about the implementation of Plugin2. Seems it uses a normal method instead of a class constructor.

Can I do so? Is there any cons?

Is it a normal-used ‘pattern’? If it is, what’s the pattern name? ‘Duck typing’? Should I avoid usage like this?

UPDATE: My concern is for below method:

def addPlugin(name, plugin)

Now parameter plugin could be either a Class or a Method. Then it is kind of obscure for the plugin developer. Is this a common case in dynamic programming language world?

class MyFramework(object):
   _plugins = {}
   _osType = None
   @staticmethod
   def addPlugin(name, plugin):
      MyFramework._plugins[name]= plugin

   def __init__(self, osType):
      self._osType = osType
      for name, plugin in MyFramework._plugins.items():
         setattr(self, name, plugin(self, self._osType))

class Plugin1(object):
   def __init__(self, owner, osType):
      self.owner= owner
      self.osType = osType
   def hello(self):
      print 'this is plugin1'

def Plugin2(owner, osType):
   if (osType == "Linux"):
      return Plugin2Linux(owner)
   else:
      return Plugin2Common(owner)

class Plugin2Linux(object):
   def __init__(self, owner):
      self.owner= owner
   def hello(self):
      print 'this is plugin2 Linux version'

class Plugin2Common(object):
   def __init__(self, owner):
      self.owner= owner
   def hello(self):
      print 'this is plugin2 common version'

MyFramework.addPlugin("plugin1", Plugin1)
MyFramework.addPlugin("plugin2", Plugin2)

framework = MyFramework("Linux")

plugin1 = getattr(framework, "plugin1")
plugin2 = getattr(framework, "plugin2")

plugin1.hello()
plugin2.hello()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:47:41+00:00Added an answer on May 26, 2026 at 7:47 pm

    This is an often-used pattern called a factory function. It’s a good idea to have your interface open to any callable that returns an object, whether the callable is a function or a class. It keeps you flexible for whatever you want to do in the future.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having implemented CLogClass to make decent logging I also defined macro, but it works
I implemented strstr() myself,the code works fine for all strings but when the string
I implemented in my app MFMessageComposeViewController for send sms. It works well, but I
I implemented OpenID support for an ASP.Net 2.0 web application and everything seems to
I implemented a quick search in my application. But when I turned the screen,
I implemented RestSharp succesfully in my WP7 application, but one issue remains: When I
I implemented background location tracking using standard location services, and it works fine. However,
I implemented my Cub3r like this <script type=text/javascript> var flashvars = {}; flashvars.xml =
I implemented a custom list view, but now there's no visual feedback that an
I implemented a simple dialog form using JQuery on GAE. It works perfectly on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.