What are the best resources if you wanted to create an application with modularization? [closed]

微笑、不失礼 提交于 2019-12-03 03:51:32

There are two ways to go around here, which one to take depends on how will your software behave.

One way is the plugin route, where people can install new code into the application modifying the relevant aspects. This route demands your application is installable and not only offered as a service (or else that you install and review code sent in by third parties, a nightmare).

The other way is to offer an API, which can be called by the relevant parties and make the application transfer control to code located elsewhere (a la Facebook apps) or make the application to do as the API commands enable the developer (a la Google Maps).

Even though the mechanisms vary and how to actually implement them differ, you have to, in any case, define

  • What freedom will I let the users have?
  • What services will I offer for programmers to customize the application?

and the most important thing:

  • How to enable this in my code while remaining secure and robust. This is usually done by sandboxing the code, validating inputs and potentially offering limited capabilities to the users.

In this context, hooks are predefined places in the code that call all the registered plugins' hook function, if defined, modifying the standard behavior of the application. For example, if you have a function that renders a background you can have

function renderBackground() {
    foreach (Plugin p in getRegisteredPlugins()) {
        if (p.rendersBackground) p.renderBackground();
    }
    //Standard background code if nothing got executed (or it still runs, 
    //according to needs)
}

In this case you have the 'renderBackground' hook that plugins can implement to change the background.

In an API way, the user application would call your service to get the background rendered

//other code
Background b = Salesforce2.AjaxRequest('getBackground',RGB(255,10,0));
//the app now has the result of calling you

This is all also related to the Hollywood principle, which is a good thing to apply, but sometimes it's just not practical.

The Plugin pattern from P of EAA is probably what you are after. Create a public interface for your service to which plugins (modules) can integrate to ad-hoc at runtime.

This is called a component architecture. It's really quite a big area, but some of the key important things here are:

  • composition of components (container components can contain any other component)
    • for example a grid should be able to contain other grids, or any other components
  • programming by interface (components are interacted with through known interfaces)
    • for example a view system that might ask a component to render itself (say in HTML, or it might be passed a render area and ask the view to draw into it directly
  • extensive use of dynamic registries (when a plugin is loaded, it registers itself with the appropriate registries)
  • a system for passing events to components (such as mouse clicks, cursor enter etc)
  • a notification
  • user management

and much much more!

If you're hosting the application, publish (and dogfood) a RESTful API.

If you're distributing software, look at OSGi.

Here's a small video that at least will give you some hints; the Lego Process [less than 2 minutes long]

There's also a complete recipe for how to create your own framework based extensively on Modularization...

The most important key element to make modularized software is to remember that it's purely [mostly] a matter of how loosely coupled you can create your systems. The more loosely coupled, the easier it is to modularize...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!