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
| # Consider this example to illustrate the Open-Closed Principle (OCP): | |
| # | |
| # Let's say you a have a client SomeClient that uses | |
| # a class DatabaseConnection to connect to the database and do something. | |
| # | |
| class SomeClient | |
| def do_something | |
| params = [:mysql, 'host', 1234, 'dbname', 'user', 'pass'] | |
| connection = DatabaseConnection.new(*params).connect | |
| end |
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
| # Consider this Rails example to illustrate the Single Responsability Principle(SRP): | |
| # | |
| # Domain information: | |
| # - A document has a number and needs one vinculated process and may have | |
| # many involveds (people involved in the document's matters) on it. | |
| # - A document can only be created if a process is given. | |
| # - The process can only be created if the document was created too. | |
| # - There are some other rules to create a document and them may change in the future. | |
| # For example, the informed document number needs to be checked agains an external system before saving. | |
| # |
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
| """ | |
| This code exemplify the use of metaclasses, decorators and signals in python3 | |
| """ | |
| def logged(function): | |
| """ | |
| Decorator to log the creation of an object of class with given arguments | |
| """ | |
| def decorator(cls, *args, **kwargs): | |
| print('Object of class %s created!' % cls) |
NewerOlder