Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interface programming

Background

A developer on my team has implemented an application which I was reviewing. He has used interfaces everywhere. The app has typical service layer, data layer and POCO objects passed from website down to DB.


Assumption

IOC used (through Unity) to inject a runtime concrete Service and Data class. All POCOs have nothing but get and set methods on public properties.


Question

I understand why an interface is used at the Service and Data layer but why would you use interfaces on all POCO objects? Is this overkill?

like image 479
Alan Alcock Avatar asked Mar 03 '26 11:03

Alan Alcock


2 Answers

Do the POCO interfaces serve a purpose? If yes, they may not be overkill. However, if they are not used, they violate the YAGNI principle.

However, on a more general note, I'm beginning to think that properties on interfaces are design smells, as they violate the Law of Demeter.

I recently posted some thoughts on better abstractions.

like image 101
Mark Seemann Avatar answered Mar 04 '26 23:03

Mark Seemann


It looks like your POCOs are used simply as Data Transfer Objects. If that's the case, they're just carrying information, with no behavior. Creating interfaces for them is overkill.

like image 28
Jordão Avatar answered Mar 05 '26 00:03

Jordão



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!