日期:2014-05-20  浏览次数:20682 次

看看人家老外是怎么讲面向对象的多态的,非常生动
Polymorphism   shouldn 't   be   a   new   concept   to   anybody.   You   deal   with   it   every   day   in   the   real   world.   There 's   more   than   one   class   of   cat   to   skin,   but   you   skin   'em   the   same   way,   even   if   the   specific   instance   is   completely   new   to   you.   Let 's   say   for   example   you   want   to   fuck   a   hole.   You   fuck   all   holes   the   same.   You   don 't   care   if   that   hole   happens   to   be   a   mouth,   an   ass,   or   a   pussy,   you 're   gonna   fuck   it   the   same   way   regardless.   However,   the   mouth,   pussy,   or   ass   may   respond   differently   to   the   fucking.
So   you   have   a   common   abstract   class   named   'Hole '   and   3   concrete   classes   Pussy,   Ass,   and   Mouth   which   all   extend   from   Hole:


class   Pussy   extends   Hole   {}
class   Mouth   extends   Hole   {}
class   Ass   extends   Hole   {}


So,   now   let 's   say   you   have   a   Penis.Fuck(Hole   h)   method.   The   Penis   class   is   unconcerned   about   what   the   specific   Hole   instance   is,   it 's   gonna   fuck   it   the   same   regardless.   Specificly   we   thrust   the   Hole   with   a   Penis   until   the   Penis   is   spent.   Finally,   we   give   the   hole   the   Penis '   load.


class   Penis   {
    public   Fuck(Hole   h)   {
        while(!this.isSpent)   {
            h.TakeAThrust(this);
            this.arousal++;
        }
        h.TakeALoad(this.load);
    }
}


Now   here 's   where   polymorphism   gets   fun.   The   Hole   will   respond   different   to   the   thrusting   and   load   depending   on   what   specific   type   of   Hole   we 're   implementing.

First   we   must   implement   an   abstract   class   which   defines   an   abstract   interface.


abstract   class   Hole   {
    public   abstract   void   TakeAThrust(Penis   p);

    public   abstract   void   TakeALoad(Load   l);
}


Now   all   that 's   left   is   the   varying   implementations   of   these   methods   in   the   seperate   concrete   classes.   For   example,   an   Ass '   implementation   of   TakeAThrust   could   look   something   like:


public   void   TakeAThrust(Penis   p)   {