Is it bad practice to have FooObject and FooObjectSummary?

I have a service where users can upload/download/replace/delete files. These files have about a dozen attributes that are saved to a SQL Database. Periodicaly throughout their session they will have to download a summary (FileName, size0in-KB, and ID) of a subset of files.

When working in the service it creates an object of these attributes (FooObject) in the DB. But, when the info is sent to the User, a summary object (FooObjectSummary) is created. FooObjectSummary has 3 attributes, FooObject has 12 or so (none of the attributes are anything but strings or primitive types).

I originaliy did this so that as little extra info would be transferred across. None of this extra data in FooObject would be dangerous for the user to have, but it wouldn’t be exposed to them anyways?

Am I just writing extra code? Or is it good practice to only expose the user to as much info as they need and not a bit more?

As with all things, it depends.

The Interface Segregation Principle indicates you should probably have the two views into the data so that you’re not breaking consumers if one of the non-vital properties is changed.

In general, you shouldn’t share the interface that you use to get at the database with consumers. What happens when you want to change how the data is stored, but keep the consumer interface the same? Though not obvious the gist of the Single Responsibility Principle applies here too.

All that said, if that interface really is going to be the same (if you change either the consumer interface or the SQL interface both are going to need to change regardless [your service is just a pass-thru]) and the extra data really isn’t big or important then saving the time and complexity might be best.

You’ll need to weigh the time saved versus the likelihood that violating the two principles will bite you in the ass later on.

I can see why you’ve gone down the path you have and understand your reasons for doing it. After all why go and get twelve properties when you’re only going to use three. Why send an object with twelve properties when you are only going to display three. It just feels tidier to do it the way you have.

I’m not going to say you are right or wrong. All I’d say is that if more and more properties start being added to FooObjectSummary then it starts to look like needless duplication. Right now I’d say it’s something to be aware of, but I’m sure you’ve got other more pressing issues.

It’ll be interesting to know what others think though.

Don’t Confuse Server Interfaces With Inner Interfaces

The client interacts with the server and exchanges data based upon the published interface for that server. What the server does to create that data doesn’t matter to the client, and the server should not send unwanted or useless data that only pertains to the server.

While the server maintains an inner object called FooObject and sends a FooObjectSummary. The two really are not the same thing. One is an inner data model that relates to database storage, and the other is a communications response to be sent to the client.

If you alter your class names, then things start to become more clear. FooObject is renamed to FooModel and FooObjectSummary is renamed to FooResponse. Now you centralize your code so that only FooModel is used to create a FooResponse.

 class FooModel
 {
      public FooResponse getResponse() {....}
 }

You can now document that the server will only send response objects for requesting data.

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