We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
DPC2019: Beyond design patterns and principles - writing good OO code - Matthias Noback
Write good object-oriented code by mastering constructor arguments, inheritance, strictness, testing, and collaboration. Learn best practices and principles for simplicity, error handling, and data validation in this talk.
- It’s more important to understand how to write good object-oriented code than to learn patterns and principles. Reading a book is essential to grasp these concepts.
- Use constructor arguments to make objects responsible for their state.
- Favor functions that have a clear meaning over functions with complex conditions.
- Use the concept of inheritance to make objects responsible for their behavior.
- Emphasize strictness, as it helps to find mistakes and maintain code quality.
- Test constructors thoroughly to ensure the correctness of your code.
- Encourage collaboration and communication among team members.
- Focus on behaviors rather than state.
- Define clear boundaries between classes and interfaces.
- Control instance creation and state by using constructors.
- Best practices and principles are more important than patterns.
- Provide the right data and the right number of values in constructors.
- Consider testing frameworks like PHPUnit or mocker.
- Implement automated testing with PHPUnit, combined with other frameworks like Codeception or Qum celebrant.
- Validate data and state.
- Design classes with clear responsibilities and interfaces.
- Avoid complex error handling and focus on simplicity.
- Constants and enumerations are essential for state and behavior.
- Maps and trees are useful data structures for encoding data in a concise manner.
- Follow the SOLID principles in object-oriented programming.