c# - Is this a Liskov Substitution Principle violation? -
c# - Is this a Liskov Substitution Principle violation? -
my custom button button, violating lsp?
class conditionalbutton : button { protected override void onclick(eventargs e) { if (condition()) base.onclick(e); } private bool condition() { //return true or false } }
in sentiment does violate lsp. please refer object mentor simplified definition of liskov substitution principle object mentor article:
“functions utilize pointers or references base of operations classes must able utilize objects of derived classes without knowing it.”
it seem ok can utilize conditionalbutton
button
point of view. but:
in order lsp hold, , open-closed principle, derivatives must conform behavior clients expect of base of operations classes use
and sure clients expect after clicking button, onclick
executed.
moreover, same article:
...when redefining routine [in derivative], may replace precondition weaker one, , postcondition stronger one.
in opinion, conditionalbutton
violates lsp in current form, because condition
allows click button, while logic related button won't executed. if condition
related enabled/disabled flag - not violate lsp.
c# oop solid-principles
Comments
Post a Comment