Created
August 31, 2012 02:34
-
-
Save nicholasjhenry/3548167 to your computer and use it in GitHub Desktop.
DCI for a CMS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Data: Simple classes that encapsulate properties and associations. | |
| # The only valid operations for a data object, is modify properties | |
| # and associations. | |
| class Site | |
| attr_reader :content_items | |
| def initialize | |
| @content = [] | |
| end | |
| def create_content(attributes) | |
| content_items << Content.new(attributes) | |
| end | |
| end | |
| # Another Data Object | |
| class Content | |
| attr_reader :title, :child | |
| def initialize(args) | |
| @title = args.fetch(:title) | |
| end | |
| def add_child(child) | |
| @child = child | |
| end | |
| end | |
| # Context: Representing a business concern. All the context does is modify | |
| # attributes or modify associations | |
| class CreatingContent | |
| # Roles: actors participating in the business concern | |
| attr_reader :content_repository | |
| def initialize(content_repository) | |
| @content_repository = args.fetch(:content_repository) | |
| end | |
| def call(attributes) | |
| content_repository.create_content(attributes) | |
| end | |
| end | |
| # Another Context | |
| class Publishing | |
| # Roles: actors participating in the business concern | |
| attr_reader :parent_content, :child_content | |
| def initialize(args) | |
| @parent_content = args.fetch(:parent_content) | |
| @child_content = args.fetch(:child_content) | |
| end | |
| def call | |
| parent_content.add_child(@child_content) | |
| end | |
| end | |
| site = Site.new | |
| creating_content = CreatingContent.new(site) | |
| parent = creating_content.call(title: "Parent Content") | |
| child = creating_content.call(title: "Child Content") | |
| publishing = Publishing.new(parent_content: parent, child_content: child) | |
| publishing.call |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment