Search This Blog

Showing posts with label OOP. Show all posts
Showing posts with label OOP. Show all posts

Tuesday, June 25, 2013

polymorfism in ANSI C

The key point here is to create Virtual Tables (xxx_vtables) in which you can have the chance to use pointer to function 
"const char* (*sound)();"


#include 

struct animal_vtable {
    const char* (*sound)();
};

struct animal {
    struct animal_vtable methods;
    const char* name;
};

const char* cat_sound() {
    return "meow!";
}

const char* dog_sound() {
    return "bark!";
}

void describe(struct animal *a) {
    printf("%s makes \"%s\" sound.\n", a->name, a->methods.sound());
}

struct animal cat = {{&cat_sound}, "cat"};
struct animal dog = {{&dog_sound}, "dog"};

int main() {
    describe(&cat);
    describe(&dog);

    return 0;
}
}

Friday, June 21, 2013

Principle Inversion of Control

In software engineering, inversion of control (IoC) is a programming technique, expressed here in terms of object-oriented programming, in which object coupling is bound at run time by an assembler object and is typically not known at compile time using static analysis.

In object-oriented programming, there are several basic techniques to implement inversion of control. These are:
  1. using a factory pattern
  2. using a service locator pattern
  3. using a dependency injection, for example:
    1. a constructor injection
    2. parameter injection
    3. a setter injection
    4. an interface injection
  4. using a contextualized lookup
see more about dependency injection

http://www.c-sharpcorner.com/UploadFile/akkiraju/dependency-injection-techniques-explained-part-1/

About Me

An seasoned developer, architect and with some Team Leading exposure, offering full project life cycle experiences within multi cultural, multi National environments and within differing business streams and all primarily on a .Net platform.