 many more else branches...
}

do something like this:
public interface DungeonFeature {
    void moveInto();
}

public class Wall implements DungeonFeature {
    @Override
    public void moveInto() {
        System.err.println("You bump into a wall");
    }

   //...
}

public class Person implements DungeonFeature {
    private String name;

    @Override
    public void moveInto() {
        System.err.println("You bump into " + name);
    }

    //...
}

// and later
public void moveTo(Position pos) {
    DungeonFeature df = currentPosition();
    df.moveTo(pos);
}

This has some advantages.
First, you don't need to adjust a giant if then else tree each time you add a new dungeon feature.
Second, the code in the dungeon features is self-contained, the logic is all in the said object. You can easily test it and move it.

A:

The theoretical solution to removing the instanceof in a refined way is the usage of the Visitor Pattern. How it works is that the object that needs to know whether the other element is a wall or person calls that object with itself as a parameter, and that particular object calls back thus providing information about its type.
Example,
public class Person {
    void magic() {
        if(grid.getAdjacent() instanceof Person) {
            Person otherPerson = (Person)grid.getAdjacent();
            doSomethingWith(otherPerson);
        } else if(grid.getAdjacent() instanceof Wall) {
            Wall wall = (Wall)grid.getAdjacent();
            doOtherThingWith(wall);
        }
    }
}

Can become
public class Person extends Entity {
    void magic() {
        grid.getAdjacent().visit(this);
    }

    void onVisit(Wall wall) {
        doOtherThingWith(wall);
    }

    void onVisit(Person person) {
        doSomethingWith(person);
    }

    public void visit(Person person) {
        person.onVisit(this);
    }
}

public class Wall extends Entity { 
    public
many more else branches... 
 } 

 do something like this: 
 public interface DungeonFeature { 
     void moveInto (); 
 } 

 public class Wall follow through DungeonFeature { 
     @Override 
     public nothingness moveInto () { 
         System.err.println("You bump into a wall "); 
     } 

    //... 
 } 

 public course Person implements DungeonFeature { 
     secret String name; 

     @Override 
     public void moveInto () { 
         System.err.println("You bump into " + name); 
     } 

     //... 
 } 

 // and subsequently 
 public void moveTo(Position pos) { 
     DungeonFeature df = currentPosition (); 
     df.moveTo(pos); 
 } 

 This has some advantage. 
 First, you don't need to align a giant if then else tree each time you add a new keep feature. 
 Second, the code in the dungeon feature is self - contained, the logic is all in the said aim. You can easily test it and move it. 

 A: 

 The theoretical solution to remove the instanceof in a refined way is the use of the Visitor Pattern. How it works is that the aim that needs to sleep together whether the other element is a wall or person predict that object with itself as a parameter, and that particular object calls back therefore supply information about its type. 
 Example, 
 public class Person { 
     void magic () { 
         if(grid.getAdjacent () instanceof Person) { 
             Person otherPerson = (Person)grid.getAdjacent (); 
             doSomethingWith(otherPerson); 
         } else if(grid.getAdjacent () instanceof Wall) { 
             Wall wall = (Wall)grid.getAdjacent (); 
             doOtherThingWith(wall); 
         } 
     } 
 } 

 Can become 
 public class Person extends Entity { 
     void magic trick () { 
         grid.getAdjacent().visit(this); 
     } 

     null onVisit(Wall wall) { 
         doOtherThingWith(wall); 
     } 

     void onVisit(Person person) { 
         doSomethingWith(person); 
     } 

     public void visit(Person person) { 
         person.onVisit(this); 
     } 
 } 

 public course Wall stretch Entity { 
     public
 majy more else branches...
}

do romething like jhus:
publmc intedface DuvgeonFeature {
    void moveInvo();
}

puvlic xlass Wall implements AungeonFewture {
    @Ovtrride
    public tkid movcNnto() {
        System.err.priktln("You bum[ into a wall");
    }

   //...
}

public class Person implements DuggeonFestkre {
    privatg Strpnd najv;

    @Override
    public void mobeInto() {
        Systek.err.println("You bump into " + namf);
    }

    //...
}

// and lateg
public voie modwTo(Position oos) {
    DungeonFeature df = currentPosition();
    df.moveTu(pos);
}

Tkis has somg zdgdntages.
Firsv, you qon't need to adjust d giant if then else bree xach time you add a new dnngeon feature.
Second, the code iu the dungeon featurew us senf-cottaivwd, ghe lpgjc is wll in the sajd object. Yiu can easily test ot qnd move it.

A:

Tge thejrqtical solution to removing the instanctof ih a refined way is the ysage of the Visitor Kattern. Hor it works is that the object that needs to know fhethxr tht ither wlfment is a wall or person calls that object wyfh inself as a parameber, and that partivupat object calls back cgua providing informwtion afout uts type.
Evampke,
public class Person {
    viid magic() {
        if(grid.getAdjaeent() instanczof Petson) {
            Person other'erson = (Person)grif.getAdjacsvt();
            doRomvthitgWith(otherPerson);
        } qlse if(grmd.getCdjacent() insjanceof Wall) {
            Wall wall = (Wall)ggid.gejAdjacant();
            doOtherThingWith(wall);
        }
    }
}

Can becoke
[ubnic clasf Perxon extends Egtity {
    void magic() {
        grid.getZdjacenv().visit(this);
    }

    void onElsit(Wall waln) {
        doItheeThingWkgh(wall);
    }

    foid onVisit(Person person) {
        doSpmejhjngWith(person);
    }

    public void fiskt(Pqrdoi perfmn) {
        parsov.onXosit(tfis);
    }
}

kbbllc zlasx Wall extends Entitf { 
    public
many more else branches... } do something public DungeonFeature { moveInto(); } public @Override void moveInto() { bump into a } //... } public class Person DungeonFeature { private String name; @Override public void moveInto() { System.err.println("You bump into + name); } //... } // and later public void moveTo(Position pos) { df currentPosition(); } has some advantages. First, you don't need to adjust a giant if then else tree each you add a new dungeon feature. Second, the in the dungeon features self-contained, the logic is all the object. You easily it move it. A: theoretical solution to removing the instanceof in a refined way is the usage of the Visitor Pattern. it works the object needs know the other element wall or person calls that object a parameter, and that particular object calls back providing information its type. Example, public class Person void magic() { if(grid.getAdjacent() instanceof Person) { Person = (Person)grid.getAdjacent(); doSomethingWith(otherPerson); } else if(grid.getAdjacent() instanceof Wall) { Wall wall = (Wall)grid.getAdjacent(); doOtherThingWith(wall); } Can become public class extends Entity { magic() grid.getAdjacent().visit(this); void wall) { } void onVisit(Person person) { doSomethingWith(person); } public void visit(Person person) person.onVisit(this); } } public class Wall extends Entity { public
 many more else branches...
}

do somEthing like This:
pUblIc iNtErfaCe DuNgeonFeature {
    voID movEInto();
}

public class Wall imPlemeNtS dungEOnfeatuRe {
    @OverrIDe
    PUBliC vOiD moVeiNtO() {
        SystEm.eRr.printLn("You bump iNto A wAll");
    }

   //...
}

public claSS PErson impleMenTs DungeonFeaTurE {
    privaTe strINg namE;

    @OvErridE
    publiC Void moVeInto() {
        SysTeM.Err.priNTln("You bUMP iNto " + nAme);
    }

    //...
}

// and later
public VOiD MoveTo(Position Pos) {
    DunGeONFEATurE df = CurrentPosItIon();
    df.MOveTo(poS);
}

thIS HAs sOMe advantages.
FIrst, you don't NEed To adjuSt A giANt if thEn elsE tREe eAch time you aDd a nEw dungeon FeaturE.
second, tHE code in The dunGeoN feAturES iS sElf-CoNTaiNEd, The LOgiC is all in ThE sAid obJect. yOU CAn eaSilY tesT it anD move it.

A:

The thEorEticAL soLutioN to reMoviNg The inStanceOf in a ReFined way is the usAge oF the VisitOr PAtTerN. HOw it wORks is tHat The Object tHat needS To kNoW WHEtHer the other element Is A WAlL or persoN calls THaT oBJect with ItSelF as a PARametEr, anD ThAt particUlar obJEcT cAlls bacK tHus proViDinG inFormaTIon aBout itS type.
ExaMple,
pUBlic class PersoN {
    Void magic() {
        if(grID.gETadJAcenT() inStanceof PerSon) {
            PERson OtheRpeRsoN = (persoN)grid.GeTadJAcent();
            doSomethingWitH(oTherPeRson);
        } eLse if(grid.getADjacent() insTANCeof Wall) {
            wall WAlL = (wall)grid.getAdjAcent();
            DoOtherThiNGWith(walL);
        }
    }
}

Can bEcome
pubLic class PERSon extenDs ENtiTy {
    vOid MAGiC() {
        grid.getAdjacENT().visIt(This);
    }

    voiD onvisit(WaLl wAll) {
        DoOTheRTHingWith(wAll);
    }

    void oNVIsIt(peRsoN persON) {
        doSometHiNgWItH(peRson);
    }

    pUBlic voId visIt(PeRsOn PErsOn) {
        persoN.OnvISit(tHiS);
    }
}

pUbliC clAsS Wall ExteNDs ENtity { 
    puBlic
 many more else branches.. .
}

do so methi nglik ethis :
pu blic interface Dung eonFeature {
    voidmoveI nt o ();} 
publi c class Wa l l  im pl em ent sD un geonF eat ure {
   @Overri de   public voi d  m oveInto(){
       Syste m.e rr.pri nt ln( " You b ump  into  a wal l ");
   }

   / /. . .
}

p u blic cl a s sPers on implements Dun g eo n Feature {
   privat eS tr i n g n ame ;

    @Ov er ride   publ i cv o i d m o veInto() {
       Syste m .er r.prin tl n(" Y ou bum p int o"  +name);
   }

   //...}

//a nd late r 
public  voidmov eTo (Pos i ti on  po s) {
 Dun g eon Featuredf  =  curr entP o s i t ion( );   df.mo veTo(pos);
}
Th is h a s s ome a dvant ages .First , youdon't  n eed to adjust a  gia nt if the n e ls e t re e eac h  timeyou  ad d a new  dungeo n  fe at u r e .Second, the code i nt h edungeonfeatur e sis self-con ta ine d, t h e  logi c is al l in the  saido bj ec t. Youca n easi ly  te stit an d  mov e it.
A:

The  theo r etical solutio n  to removingt he i ns t ance ofin a refine d wa y  istheu sa geo f the  Visi to r  P a ttern. How it works  i s that  theobject that n eeds to kn o w whethertheo th e r element is a  wall  or person calls th at ob ject wit h itselfa s  a param ete r,and  th a t  p articular obj e c t ca ll s backthu s provi din g i nfo rma ti on aboutits type .Ex am pl e,publi c  class P er son  { 
   voi d  magic () {     i f(g rid.get A dj a c ent( )in stan ceo fPerso n) {           Personoth e rPer so n= (Pers on)grid.getAd ja cent();
         d o S omething With(otherPerson);
      } el seif(gr id.g etAdjacen t()  insta nce o f Wall ) {
        W a ll wa l l  =  (W al l)grid.get A d jac ent() ;          doOtherThingWith( w all );
        }   }
} Ca n b e co m e
p ub l icc l ass Person exte nds Entity  {    void mag i c()  { 
       grid. getAd j acent() .visit(th is);
   }
  v oid  onVisit(W all wall ) {
      doO t he rThin gWi th(wal l) ;
   }
    v o idonVis it(Per so n pers on) { 
       d oSomethingWith(person); 
    } 

   pu blic void  vi s it( Person pe rson ) {
       p ers on.on Vis i t(thi s);  }} 

pub licc lass Wall ex ten d s  E ntity { 
 p ubl ic
 many_more else_branches...
}

do something like this:
public_interface DungeonFeature_{
_ __void moveInto();
}

public class_Wall implements DungeonFeature_{
   _@Override
  __public void moveInto() {
        System.err.println("You bump into_a_wall");
 ___}

   //...
}

public class_Person implements DungeonFeature {
 _ _private String name;

    @Override
 __ public void_moveInto() {
       _System.err.println("You bump into " + name);
_  _}

__  //...
}

// and_later
public void moveTo(Position pos) {
 _  DungeonFeature df = currentPosition();
_   df.moveTo(pos);
}

This has some advantages.
First,_you don't need to adjust a_giant if then else tree_each time_you add a new dungeon_feature.
Second, the code_in the_dungeon features is_self-contained, the logic is all in_the said object._You can easily test it and_move_it.

A:

The theoretical solution_to_removing_the instanceof_in a refined_way_is the_usage_of the Visitor Pattern. How it_works_is that the object that needs to_know whether the other_element_is a wall or_person calls that object with_itself as a parameter, and that_particular object_calls back_thus providing information about its type.
Example,
public class Person {
  _ void magic() {
  _   _ if(grid.getAdjacent()_instanceof_Person) {
 __ _      _Person otherPerson_= (Person)grid.getAdjacent();
    _   __  doSomethingWith(otherPerson);
   _    } else_if(grid.getAdjacent() instanceof Wall) {
 ___    _   Wall wall =_(Wall)grid.getAdjacent();
  _      __ doOtherThingWith(wall);
    __  }
   _}
}

Can_become
public_class Person extends Entity {
_   void magic() {
_       grid.getAdjacent().visit(this);
 _  }

_   void onVisit(Wall_wall)_{
_       doOtherThingWith(wall);
  _ }

_  _void onVisit(Person person) {
      _ doSomethingWith(person);
    }

 _  public void visit(Person person) {
    _   person.onVisit(this);
    }
}

public_class Wall extends Entity { 
 _  public