Separation of concerns: Whose concern is this?

My senior reviewer colleague wants me to do the following.

We have (on iOS, iPhone) a hierarchy of views in one of our screens. There is a simple rectangle that represents a Business card of a person (visually matches business cards style).

As this card is reused many times in many screens, I have written a custom class called PFXBusinessCard that has four labels, each label representing person’s data like Name, Phone number, account and email. These four labels are exposed as properties of that custom class.

In my controller, I am passing the data for a particular label in a following manner.
I get the person, read the particular value for a property and set this property in a controller. That is, I am setting the name, phone number etc..

But my colleague says I should instead handle this inside the PFXBusinessCard class.
I should create a populateWithPersonsData method in the class, and I would just pass a person to the card in my controller. The card would then populate its labels itself.

Is this approach ok? Why would the card should know about the person? The UI object should not know anything about the data. Should it?

This is an issue that can be debated forever and in the end, both sides might be right.

There are two schools of thought in the application of the MVC pattern, which is what your question boils down to. I would name them the schools of the dumb View and the smart View.

In the dumb View, the View should concern itself only with UI matters and should not contain any logic (with the possible exception of iterating over a collection of values it needs to show). The controller is responsible for handing the data in bite-sized chunks to the View.

In the smart View, the View is allowed to have a limited amount of logic in it. In particular, the logic to convert objects from the Model into displayable values.

In my opinion, the smart View most closely resembles the formulation of the MVC pattern and should be preferred. It seems to me that the dumb View came about because for some it was too tempting to put business logic in the View (which does not belong there) and because it seemed that the Controller was losing its function.

4

What if you create category

@interface PFXBusinessCard (PersonData)
- (void)populateWithPersonsData:(PersonData *)personData
@end

so your View class is not aware of Model class, but all this logic is still encapsulated, and you keep it DRY. It’s subject to discuss.

The card should know the person if displaying the person data is one thing it will do. Your colleague is right IMHO, because there must be logic for displaying PersonData somewhere in the whole code base. If controller wouldn’t do it, so it belongs to the consumer of caller to map every properties of PersonData to your controller, and this logic will be scattered in your codebase. Any OOP design should bring more quality to the overall codebase, not reducing it.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật