Skip to content

iqiyi/Navi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
        // ...
    }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages