A Ruby library for encapsulating business logic using DCI patterns, allowing objects to gain context-specific behaviors.
Surrounded is a Ruby library that implements the Data, Context, and Interaction (DCI) pattern to encapsulate business logic. It allows developers to group objects into contexts where they assume specific roles and gain behaviors only when needed, solving the problem of scattered logic and tight coupling in object-oriented systems.
Ruby developers building complex applications who need to manage business logic cleanly, especially those interested in DCI, domain-driven design, or improving object encapsulation.
Developers choose Surrounded because it provides a structured way to keep behaviors cohesive and context-specific, reducing the complexity of objects by avoiding monolithic classes and promoting better separation of concerns.
Create encapsulated systems of objects and focus on their interactions
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Groups objects into contexts where they gain role-specific behaviors only when needed, as shown in the Employment example where employee and boss methods are isolated to the context.
Supports modules, SimpleDelegator wrappers, or interface objects for applying behaviors, allowing developers to choose the best fit, detailed in the 'Managing Roles' section.
Provides a DSL for defining triggers that automatically handle context access, with features like forward_trigger and protect_triggers for controlled execution and permission-based logic.
Enforces Tell, Don't Ask principles by making triggers return the context object, promoting better encapsulation and reducing state leakage, as explained in the 'Restricting return values' section.
Requires understanding of DCI, advanced Ruby metaprogramming, and the library's DSL, which can be daunting for teams not already familiar with these concepts.
Demands including Surrounded in all role player classes and carefully defining contexts with initialize and role methods, adding overhead compared to simpler patterns.
Relies on method_missing for implicit object access and dynamic behavior application, which could introduce latency in high-performance or real-time applications.
As a niche DCI implementation, it has fewer resources, community examples, and integrations compared to more common Ruby patterns, making troubleshooting harder.