How to develop a web application with a bunch of feature modules

105 views Asked by At

I am developing a web application using spring framework and google app engine. I am wondering if there is a design pattern or framework with the help of which I can develop features of my application as pluggable modules. For example I have identified 4 features of the application:

  1. Oauth Login
  2. User Profile Management
  3. User Group creation
  4. User File management

Now what I need is to develop all these features as independent modules, so that i can detach any of them dynamically and they are as loosely coupled as possible. They can have their own database implementation, their own set of technologies etc. Is there a design principle to implement modules in such a way.

3

There are 3 answers

2
retroq On BEST ANSWER

You can take a look at MQ systems (such as RabbitMQ, ActiveMQ). MQ system will work as intermediate layer, which provide you loosely coupling. Communication between modules will be implemented as posting messages to queue and listening for posting.

Also, OSGI may help you. It gives you possibility to make your application as a set of pluggable modules, which might be loaded dynamically.

0
Chowdappa On

As per my experience, I suggest, Use MVC pattern. Use Servlet filttersfor 1.Oauth Login. Create service/POJOs to implement and inject each other according to your requirement for 2.User Profile Management 3.User Group creation 4.User File management

If you know Spring AOP, use. So that you can achive more dynamic integration between implementations of points 2,3, and 4.

0
Soteric On

You should split the feature in two components: API and implementation. The first one contain interfaces, the second their implementations. You pass the interface to web app controller and inject implementation via Spring or any other Dependency Injection framework. For example

web-app, UserController which handles requests from client and delegate to your components

@Component
public class UserController {
    private FileManager fileManager;

    @Autowired
    public UserController(FileManager fileManager) {
        this.fileManager = fileManager;
    }

    @GET("/user/{userId}/file/{fileId}")
    public File getUserFile(long userId, long fileId) {
        fileManager.getUserFile(userId, fileId);
    }
}

file-mgt-api where you define interfaces to decouple web-app from implementation

public interface FileManager {
    File getUserFile(long userId, long fileId);
}

file-mgt-impl where all the details of how to get requested file

@Component
public class FileManagerImpl implements FileManager {
    @Override
    public File getUserFile(long userId, long fileId) {
        // get file by id from DB
        // verify that provided user is the file owner
        // do other useful stuff
        // return the file or throw exception if something wrong
    }
}

Do the same for group, profile management and other features. After that you can easily replace implementation by replacing single jar file. Your web-app is completely decoupled and don't know anything about implementation details, it only depends on interfaces.