0

I have a class which adds some functionality to a windows form textbox. For example, it handles textbox key down event and based on some sort of logic, if 'Enter' was pressed then an special grid is shown to let the user select one entity from a large number of entities. So I call this class 'Textbox Extender' and the textbox 'Extended'.

Now, I want to make the user informed that whether a textbox is extended by changing it's back color, pretty easy to add this functionality to the class BUT: I am very suspecious it is against Single Responsibility Principle. Any idea is highly appreciated.

Alireza
  • 10,237
  • 6
  • 43
  • 59

2 Answers2

0

Its not against ssr. Your class responsibility is to extend textbox functionailty.

athabaska
  • 455
  • 3
  • 22
  • But now it has two responsibilities: Extending the textbox, changing backcolor. Perhaps tomorrow changing the font. Another day changing the forecolor. What's your idead? – Alireza Jun 13 '13 at 07:13
  • 1
    Hah! Then think about usual text box - its has ZILLIIONS of responsibilities: process "a" button press, print "a" char, process "b" button press, print "b" char, etc. – athabaska Jun 13 '13 at 07:15
  • I think in your case you can have a wider look at what responsibilites are. Besides, in the end of the day you want a working application, not application that satisfy all rules of "proper development", but is not working. – athabaska Jun 13 '13 at 07:17
  • Great example.Now I am convinced. Thanks. – Alireza Jun 13 '13 at 07:18
  • Actually following the rules obsessively enabled me to develop working and yet maintainable application. Working application is not that much hard to achieve these days but think about maintaining the code. – Alireza Jun 13 '13 at 07:22
  • Well, rules should be working for some people at least 8) What I meant is that process of splitting classes according to ssr can go to deep, literally to infinity and beyond. – athabaska Jun 13 '13 at 07:29
0

Single Responsibility Principle say that your class should only fullfill one purpose, what is the purpose of your class? I would say it is to show an extended TextBox(and get its data, which you can't do somewhere else), if your UI changes do inform your User that they now have an extended textbox everything is ok with that, no violation of SRP. Anyway capsuling UI from the UI object seems like overengineering.

Master117
  • 660
  • 6
  • 21
  • What do you mean by 'Anyway capsuling UI from the UI object seems like overengineering.' Nothing is capsulated in the extender class. – Alireza Jun 13 '13 at 07:24
  • you wanted to change your UI, now if it would be against srp that would mean you would have to place it in another class. And changing the UI of your Textbox from another class rather than itself seems like useless work. – Master117 Jun 13 '13 at 07:30