title: Objective c isKindOfClass missunderstanding?
body: <p>I have following structure of objects:</p>
  
  <p>Animal, Dog and Cat. As You expect Dog and Cat are inherited from Animal.</p>
  
  <p>And I've a farm class:</p>
  
  <pre><code> @implementation AnimalFarm
  
  -(Animal*) createAnimal:(AnimalType)type{
  
    switch (type) {
  
      case CAT:
        return [Cat new];
  
      case DOG:
        return [Dog new];
  
      default:
        return [Animal new];
    }
  
  }
  
  @end
  </code></pre>
  
  <p>and I tried to unit test:</p>
  
  <pre><code>  AnimalFarm *farm = [AnimalFarm new];
  
    Animal *dog = [farm createAnimal:DOG];
    Animal *cat = [farm createAnimal:CAT];
  
    STAssertTrue([cat isMemberOfClass:[Cat class]],@"cat is not a cat!");
    STAssertTrue([dog isMemberOfClass:[Dog class]],@"Dog is not a dog!");
  
    STAssertTrue([cat isKindOfClass:[Animal class]],@"Cat is not an animal!");
    STAssertTrue([dog isKindOfClass:[Animal class]],@"Cat is not an animal!");
  </code></pre>
  
  <p>Implementation of classes:</p>
  
  <pre><code>@interface Cat : Animal {
  
  }
  
  
  @end
  
  @implementation Cat
  
    -(NSString*) say{
      return @"miau";
  }
  
  @end
  </code></pre>
  
  <p>Implementation of dog is similar.</p>
  
  <p>but neither isKindOfClass or isMemberOfClass worked as I expected....</p>
  
  <p>Am I missing something?</p>
  
  <hr>
  
  <p>When I use IFs instead of switch then everything goes well ... but what is the difference?</p>
  
  <p>Implementation of createAnimal which works:</p>
  
  <pre><code>-(Animal *) createAnimal:(AnimalType)type {
  
    if (type == DOG) {
      return [Dog new]; 
    } else if (type == CAT) {
      return [Cat new]; 
    } else {
      return [Animal new];
    }
  </code></pre>