swift - Protocol oriented programming and introduction of additional properties -


i started using pop couple months ago , premise. despite allows feel inability introduce new properties cripples it. find in real world situations need introduce 1 or more property extension needs intended do. recent example this:

i have extension uiview renders special kind of border. creating new calayer , adding sublayer view. worked fine until noticed when view's bounds change, stuck old border. remedy this, wanted store border layer property , when layout changed remove old border layer , create new one. since protocols can't add properties directly, had use subclass.

i not interested how handle situation above omitted details might render improvements unusable. know if have live , revert subclasses or missing , can somehow overcome it.

i know protocols can define properties classes implementing need define well, limiting too. in example above, wanted extend functionality of uiview, not subclass of uiview, can used in view

my cheeky answer:

protocol oriented programming poor man's multiple inheritance oop language that's not got it.

so if find don't have something-or-another need in hierarchy, make protocol, , conform necessary objects it.

composition on inheritance?

or inherited composition?

probably doesn't matter.

;)

whatever works.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -