c# - What's the best alternative to an empty interface -


i apologise essay wanted set context of why i'm asking empty interfaces.

i on oop course , interesting debate arose around use of empty interfaces - team divided on whether or not code smell.

to set background, had design app valet parking service - customer brings car attendant , attendant parks car in carpark , gives customer ticket.

customers can return attendant ticket , attendant retrieve car carpark.

when designing solution, anticipated carpark may used park bikes, vans, cars , potentially obscure shipping container. drove me create interface - iparkable. way, instead of carpark containing list of cars, have list of iparkable objects.

my car , bike classes implemented iparkable interface both parked in carpark, interface empty - fyi @ time of doing this, hadn't heard of marker pattern.

my argument using interface meant objects in carpark kept hold of type - car still car , bike still bike. also, makes incredibly easy if new type needs ability parked - hooray interfaces!

however, when discussing solution team, lot of people felt empty interface big code smell , have been avoided using inheritance or else instead. people against included 1 of course facilitators.

this have meant needing vehicle class - shipping container? has nothing in common vehicle, maybe you'd need parkable class?

at point, still convinced empty interface way go.

interestingly, next requirement have cop come carpark when full , tow away dodgy cars, giving backhander carpark attendant other way - comes stuff?!

now lets have carpark 1000 objects - cars, bikes , shipping containers, cop can take cars.

with empty interface, like:

cartotow = parkedstuff.firstordefault(x => x.gettype() == typeof (car)); 

finally, come question - good, viable / better alternatives empty interface?

had used inheritance, have list of objects no longer cars, bikes etc, i'd have parkables. can't see clean way cars list without looping through using try catch blocks attempt cast objects cars.

personally, have no problem empty interface, many people view code smell, know alternatives are.

again - sorry essay!

thanks!

your question based on false assumption. if have parkable class, , list<parkable> contains cars, bikes, shipping containers, etc., objects retain runtime type of car, bicycle, or shippingcontainer if in list<iparkable>. still parkedstuff.oftype<car>().first() or whatnot.

however, doesn't resolve question value of marker interfaces, since parkable class empty iparkable interface, , of code smell -- or not.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -