Courses🔥 10th Anniversary 🔥AI WorkshopCompaniesPricingBlogConfAiBotSubscribeSign in
  • Courses
  • 🔥 10th Anniversary 🔥
  • AI Workshop
  • Companies
  • Pricing
  • Blog
  • ConfAiBot
Subscribe
  • Courses
  • Companies
  • Communities
  • Blog
  • Gift card
  • Newsletter
  • Help
  • Shop
  • ConfAiBot
  • Contact
  • Legal notice
  • General conditions
  • Privacy policy
  • Cookies policy
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium
10 years of Codely: 100 € discount on Premium

Why NOT to use getters and setters | Tell don't ask

1 October 2015 | screencasts

Do you use getters and setters? Are you familiar with anemic domain models? The Tell don't ask principle? In this video, we will learn more about these concepts! We have already touched on the application layer a bit through the screencast about the single responsibility principle, and the relationship with the infrastructure layer through the screencast about the dependency inversion principle. In this video, we will focus on the layer of our domain, specifically, the domain models.

Video Index

  • 0:19 Question: In PHP, public class attributes are accessed; should I use getters and setters?
  • 1:17 Programming principle applicable to all languages
  • 2:00 User model with public class attributes
  • 3:19 Difference between Data Transfer Object (DTO) and domain model. What is an anemic domain model?
  • 4:14 What problems arise from using public class attributes?
  • 4:50 User model as an associative array/hashmap
  • 6:00 What problems arise from using associative arrays for domain modeling?
  • 6:50 User model with private class attributes, getters, and setters (anemic model)
  • 7:17 Benefits of using getters and setters
  • 8:00 Why NOT to use getters and setters
  • 9:12 Domain model User with behavior
  • 10:47 What benefits come from using rich domain models (with behavior)?
  • 13:09 Conclusion: Neither public class attributes nor getters and setters. The ideal: Business logic where appropriate (high cohesion)

Video

Related Material

  • Tell don't ask: Article by Martin Fowler about the Tell don't ask principle
  • Tell, Don't Ask (thoughtbot): Examples of violations of the Tell don't ask principle in Ruby
  • Data Transfer Object: Article by Martin Fowler on the DTO design pattern
  • Anemic Domain Model: Article also by Martin Fowler about the anti-pattern of anemic domain models

Tags

IntermediatePHPRefactoringTell don't ask
AnteriorSoftware Craftsmanship Barcelona 2015
SiguienteInterview with Pablo Ros | Web Developer at Softonic and Uvinum

Pay according to your needs

lite (only monthly)

19 €
per month
  • Essential programming courses to build a solid foundation
  • Company invoice

standard

24,92 €
Save vs monthly of 49 €
Annual payment of 299 €
per month
  • Main catalog to master writing maintainable, scalable, and testable code
  • Receive job offers verified by Codely
  • Company invoice
Save 189 €

premium

33,25 €
Save vs monthly of 89 €
100 € anniversary discount
Annual payment of 399 €
per month
  • Exclusive AI courses to keep you always up to date
  • Early access to new courses
  • Discount on workshops
  • Receive job offers verified by Codely
  • Company invoice

We won't increase the price while your subscription is active