Architecture Overview
PlatyMap uses a multi-layered architecture:- User Interface Layer: The DSL builders that provide a fluent API for creating mappings
- Rule Layer: The rules that define how data is transformed
- Execution Layer: The context and execution engine that applies the rules to data
- Utility Layer: Helper functions, extension methods, and registry services
- The user creates a mapping using the DSL
- The DSL creates mapping rules
- The mapping is executed with source data
- The execution engine applies each rule to transform the data
- The transformed data is returned in the desired format
- Separation of Concerns: Each component has a single responsibility
- Immutability: Most objects are immutable after creation
- Fluent Interface: Method chaining for a readable API
- Composition over Inheritance: Rules are composed rather than inherited
Design Patterns Used
The PlatyMap library uses several design patterns that are important to understand:Builder Pattern
The Builder pattern is used extensively throughout the library to construct complex objects through a fluent interface. Example:flow(), withFormat(), to(), map(), and to() are all part of a builder chain that constructs a Mapping object.
Key Builder Classes:
SourceBuilderTargetBuilderMappingBuilderBranchBuilderForEachBuilder
Strategy Pattern
The Strategy pattern defines a family of algorithms, encapsulating each one, and making them interchangeable. In PlatyMap, eachMappingRule is a strategy for transforming data.
Example:
Composite Pattern
The Composite pattern composes objects into tree structures to represent part-whole hierarchies. PlatyMap uses this pattern with nested rules and branches. Example:Command Pattern
The Command pattern encapsulates a request as an object, allowing parameterization of clients with different requests. Each mapping rule acts as a command that can be executed on data.Factory Method Pattern
The Factory Method pattern defines an interface for creating an object, but lets subclasses decide which class to instantiate. PlatyMap uses factory methods to create different rule types. Example:Registry Pattern
The Registry pattern provides a central place to store objects that need to be globally accessible. TheFunctionRegistry in PlatyMap is an example:
Chain of Responsibility Pattern
The Chain of Responsibility pattern passes a request along a chain of handlers. Each handler decides to process the request or pass it to the next handler. PlatyMap uses this in its builder chain, where each builder adds to the configuration and passes control to the next builder.Package Structure
The library is organized into several packages:xyz.mahmoudahmed.dsl.core
Contains the core interfaces and classes like MappingRule, MappingContext, and Mapping.
xyz.mahmoudahmed.dsl.builders
Contains the builder classes that form the DSL.
xyz.mahmoudahmed.dsl.functions
Contains the function registry and function-related classes.
xyz.mahmoudahmed.dsl.collections
Contains classes for handling collections like ForEachMapping.
xyz.mahmoudahmed.dsl.conditional
Contains classes for conditional branching like BranchBuilder and ConditionalBranch.
xyz.mahmoudahmed.dsl.structure
Contains classes for structural operations like nesting and flattening.
xyz.mahmoudahmed.dsl.bulk
Contains classes for bulk operations like BulkMappingRule.
xyz.mahmoudahmed.dsl.typed
Contains classes for type-safe mappings with Java beans.
xyz.mahmoudahmed.dsl.util
Contains utility classes like PathMatcher.

