What is the meaning of “functionally oriented programming” (FOP) in C ++, and will it make sense in Java and C #?

Unfortunately, I can’t remember where I read it, but ... ... in C ++ you can get a class from a template parameter. I am sure this is called Functionally Oriented Programming (FOP) and should be somehow useful.

It was something like:

template <class T> class my_class : T { // some very useful stuff goes here ;) } 

My questions:

  • What is the meaning of such a picture?

  • Since this is not possible in Java / C #, how is this pattern achieved in these languages?

  • Can you expect it to be implemented in Java / C # in one day?
    (Well, the first Java would have to get rid of type erasure)

EDIT :
I'm really not talking about generics in Java / C #
(where it cannot derive a class from a type parameter)

+4
source share
3 answers

So, the place where I see that the template is the most in C ++ is the behavior of mixins ( link ), which, I think, is an implementation of FOP. The article I linked provides an example of ASP-oriented programming to try to make a similar effect in java.

I doubt that you will see features such as templates (which are necessary for the mixin approach) in other languages, although they can develop better templates for AOP. Personally, I believe that the easiest method I've seen for this is languages ​​like python and ruby ​​that allow you to manipulate the interface, but it’s a runtime mechanism for C ++ compiling time metaprogramming objects, so it’s like comparing apples and oranges.

+3
source

I have seen this pattern before, but I never knew it as function-oriented programming. I looked at the FOP here: http://wwwiti.cs.uni-magdeburg.de/iti_db/forschung/fop/featurec/ and it doesn't look like it.

The pattern that I know that does something very similar to your description is called Policy Based Design. It is discussed in detail in Modern C ++ Design by Andrei Alexandrescu. The previous poster mentioned Aspect Oriented Programming, which, in my opinion, is a small subset (mostly a one-dimensional AOP instead of an N-dimensional).

I don’t think the policy-based design will be implemented in Java or C #, but AOP seems to be for Java with AspectJ http://www.eclipse.org/aspectj/ . It looks like there have been some attempts with C #, but I did not notice anything that could be mentioned.

+1
source

AHEAD is a methodology for creating function-oriented programming, and there is a java composer. There is also an Eclipse IDE for running fop applications. You can even choose AHEAD composer (java) or featureC ++ for C ++. All of them are implemented as source compilers.

http://wwwiti.cs.uni-magdeburg.de/iti_db/research/featureide/

the meaning of this approach is that you implement functions as layers, each level is exactly one feature. Thus, in this layer, you save code that refines some of the code in the lower layers (layers / functions are ordered), and you also encode how the function interacts with other functions. There may be refinements for several classes in the layer (exactly what you would do if you had to add a certain function to your existing program), but with FOP you really do not lose the previous version. The idea is that if you disable a specific function from this assembly, it means that the code that interacts with this function is not entered, but the rest of the functions remain unchanged.

Think of it as an additional aspect of polymorphism and how you organize functionality

0
source

Source: https://habr.com/ru/post/1285745/


All Articles