Interface design and SRP

36 views
Skip to first unread message

Miroslav Genov

unread,
Sep 14, 2015, 11:38:59 AM9/14/15
to Growing Object-Oriented Software
Hello, 

Recently I was looking into interface named Source in java library named okio. 

I was tried to violate this interface with some definitions mentioned TDD With Mock Objects: 

This is the example which I'm pointing out (C#): 

[Test]
public void Send_Diagnostic_String_&_Receive_Status() 
{   
   var mockTelem=mocks.StrictMock();
   mockTelem.Stub(m => m.Connect());
   mockTelem.Stub(m => m.OnlineStatus).Return(true);
   mockTelem.Expect(m => m.Send(DiagnosticMessage));   //
}

Author says, that this is a SMELL that violates the SRP principle, cause some of the methods in the dependency are mocked, where the other one are stubbed. 

From my point of view, Source interface is having really simple and good design, but If I align it with article definition, It looks like a SMELL, cause it has methods for mocking and stubbing. 

What you guys think about this topic ? 

Steven Solomon

unread,
Sep 14, 2015, 12:03:34 PM9/14/15
to growing-object-o...@googlegroups.com
Miroslav, 

I tend to agree with you, I don't see a SRP violation here. Maybe a violation of Tell Don't Ask, given that it connects and then ask if it's online via the OnlineStatus check that is implied in the test. 

Steve

--

---
You received this message because you are subscribed to the Google Groups "Growing Object-Oriented Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to growing-object-oriente...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steve Freeman

unread,
Sep 14, 2015, 12:26:52 PM9/14/15
to growing-object-o...@googlegroups.com
To me the question is whether the status of the connection can change over time. If not, then an alternative would be for the Connect() call to return a connection fail. 

S

Sent from my iPhone
Reply all
Reply to author
Forward
0 new messages