lundi 8 juin 2020

Passing Class which implements an specific Interface

So I got the following Structure.

abstract class Item

class Apple

class Stick : Carriable

interface Carriable

void Equip(CarriableItem item)

Now I want a function where I can pass Items which implements Carraible. So that I can pass Stick but not an Apple.

I try to avoid an if inside of that function in case the Item cant be cast to Carriable.

Aucun commentaire:

Enregistrer un commentaire