Mastering Layered Java Architecture: Clear Business Logic & Clean Code
This article examines Alibaba's Java framework layering approach, detailing each tier—from open API to DAO—while offering best practices for exception handling and domain model conventions to achieve clearer business logic and more maintainable code.
Alibaba's Java framework adopts a multi‑layered architecture that clarifies business responsibilities and improves code cleanliness.
Application layers include:
Open API layer : Exposes services as RPC or HTTP interfaces, and can be accessed by the gateway control layer.
Terminal display layer : Handles template rendering for various clients (Velocity, JS, JSP, mobile, etc.).
Web layer : Performs request routing, basic parameter validation, and simple non‑reusable business processing.
Service layer : Contains specific business‑logic services.
Manager layer : Provides generic business handling, such as third‑party platform wrappers, cache or middleware utilities, and interacts with the DAO layer for common data operations.
DAO layer : Manages data access to MySQL, Oracle, HBase, or OB, and interfaces with external RPC/HTTP services.
Exception handling guidelines suggest catching generic Exception in the DAO layer, wrapping it in a DaoException, and logging at the Service or Manager layer to avoid duplicate logging and performance loss. The Web layer should not re‑throw exceptions; instead, it should direct users to friendly error pages, while the Open API layer returns standardized error codes and messages.
Domain model conventions define several object types:
DO (Data Object) : Mirrors database tables and is transferred via the DAO layer.
DTO (Data Transfer Object) : Used by Service and Manager layers for external communication.
BO (Business Object) : Encapsulates business logic output from the Service layer.
QUERY : Represents query parameters; queries with more than two parameters must avoid using generic Map objects.
VO (View Object) : Delivered from the Web layer to the template rendering engine.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITFLY8 Architecture Home
ITFLY8 Architecture Home - focused on architecture knowledge sharing and exchange, covering project management and product design. Includes large-scale distributed website architecture (high performance, high availability, caching, message queues...), design patterns, architecture patterns, big data, project management (SCRUM, PMP, Prince2), product design, and more.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
