Programming ideas

Материал из fidoman.ru

Function classes

Taking function as argument obviously requires that function have defined argument list and return value type - but nothing is said about what the function will do.

Assigning function some class may provide tool for programmer to specify, what function can be used as argument.

E.g. we want have to put on queue only functions that have meaning in this queue (different variants of uart send functions). So we require function that have class of "uart send queue". So if programmer creates functions that works in this context, he would mark it with this class "uart send queue". No other functions can be given here is result, even they have identical attribute list - but is nonsence if called here.

Polymorphism

Classic polymorphis gives us possibility to pass any of (of poly morphs) descendent classes. But nobody primises us that these classes are functioning in such way that is acceptable. And they are not so polymorphic - they all have identical inherited interface of base class.

Real polymorphism must give us ability to call totally unrelated classes that implement same function in different ways. Obviously, it is neede to have some intermediate layer modules that derive common interface from many different implementations.