How brick/math works
Main Components
a) Public API Layer:
• Main public classes (BigNumber, BigInteger, BigDecimal, BigRational)
• RoundingMode enum
• Exception hierarchy
b) Internal Calculator Layer:
• Calculator interface/abstract class
• Three calculator implementations (BcMath, GMP, Native)
Relationships and Component Organization
a) Class Hierarchy:
• BigNumber as the parent class at the top
• BigInteger, BigDecimal, and BigRational inheriting from BigNumber
b) Exception Hierarchy:
• MathException as the base exception
• Specific exceptions inheriting from it
• Exceptions visually in a separate section
c) Calculator Strategy Pattern:
• Calculator as an abstract class/interface
• Three calculator implementations
Specific Design Elements
Use these visual elements:
• Blue: Public API classes
• Green: Calculator implementations
• Red: Exceptions
• Gray: Internal/Abstract components
• Rectangles: Concrete classes
• Rounded rectangles: Abstract classes/interfaces
• Hexagons: Enums (for RoundingMode)
Important Relationships to Highlight
• How BigNumber classes use the Calculator implementations
• Factory method pattern with 'of()' methods
• Exception throwing relationships
Implementation Details
Annotations for:
• Required PHP version (8.1+)
• Optional extensions (GMP, BCMath)
• Immutability guarantees
• Type conversion rules
This architecture represents a well-structured mathematical library following the Strategy pattern for different calculator implementations, with a clear separation between public API and internal implementation details.