All Projects → iqiyi → Navi

iqiyi / Navi

Licence: Apache-2.0 License
No description, website, or topics provided.

Programming Languages

java
68154 projects - #9 most used programming language

Navi: Annotation Based Component Selector

codecov

Why?

The reason to create this project is to simplify the business system design and dev.

Why this project can make these works to be more simple? Actually, at the beginning, most of business systems are very simple, may be just a CRUD system. But along with the business growth, the logic will become to be more and more complex. For one function, amount of branches will be generated:

  1. Different client types (PC Web, H5 Web, Android, IOS, Phone, Pad, TV, XBox...)
  2. Different client versions
  3. Different countries and areas
  4. Different types of users
  5. Other business dimensions...

These different branches will have different logic, but still need to be integrated with the trunk logic. So how to organize the code? With if...else and switch? That would be a disaster for the maintainability and extendability.

With Navi, developers can implement the complex logic with elegant way.

How?

@EqualMatcher(property = "clientType", value = "android")
@VersionMatcher(range = "[1.0.0,2.0.0)")
public class AndroidV1OrderCreateHandler implements OrderCreateHandler {

}

OrderRequest request = new OrderRequest():
request.setClientType("android");
request.setVersion("1.5.0");

// this handler is AndroidOrderCreateHandler
public class OrderCreateService {
    public OrderCreateResponse createOrder(OrderRequest request) {
        // ...
        // Trunk Logic
        // ...
        
        // Branch Logic
        OrderCreateHandler handler = selector.select(request, OrderCreateHandler.class);
        handler.handle(request);
        
        // ...
        // Trunk Logic
        // ...
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].