Thursday 15 September 2011

c# - Why a class does need to implement an interface? -



c# - Why a class does need to implement an interface? -

soon writing code in .net framework, needed method can't access that. after search have learnt implement interface first. know interfaces provide differentiation or polymorphism (i think). why did .net framework want me implement interface? why necessary?

that generic handler needs ireadonlysessionstate,irequiressessionstate interfaces session usage.

as tomtom said, because designed way... why designed way? here's answer, reply why interfaces usefull.

taken here

"an interface contains definitions grouping of related functionalities class or struct can implement.

by using interfaces, can, example, include behavior multiple sources in class. capability of import in c# because language doesn't back upwards multiple inheritance of classes. in addition, must utilize interface if want simulate inheritance structs, because can't inherit struct or class."

in case implementing multiple interfaces.

as polymorphism...

"a base of operations class can implement interface members using virtual members. in case, derived class can alter interface behavior overriding virtual members. more info virtual members, see polymorphism."

c# oop

No comments:

Post a Comment