What does “abstract over” mean?

后端 未结 6 2077
醉话见心
醉话见心 2021-01-29 17:58

Often in the Scala literature, I encounter the phrase \"abstract over\", but I don\'t understand the intent. For example, Martin Odersky writes

You can p

6条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-29 18:22

    An abstraction is a sort of generalization.

    http://en.wikipedia.org/wiki/Abstraction

    Not only in Scala but many languages there is a need to have such mechanisms to reduce complexity(or at least create a hierarchy that partitions information into easier to understand pieces).

    A class is an abstraction over a simple data type. It is sort of like a basic type but actually generalizes them. So a class is more than a simple data type but has many things in common with it.

    When he says "abstracting over" he means the process by which you generalize. So if you are abstracting over methods as parameters you are generalizing the process of doing that. e.g., instead of passing methods to functions you might create some type of generalized way to handle it(such as not passing methods at all but building up a special system to deal with it).

    In this case he specifically means the process of abstracting a problem and creating a oop like solution to the problem. C has very little ability to abstract(you can do it but it gets messy real quick and the language doesn't directly support it). If you wrote it in C++ you could use oop concepts to reduce the complexity of the problem(well, it's the same complexity but the conceptualization is generally easier(at least once you learn to think in terms of abstractions)).

    e.g., If I needed a special data type that was like an int but, lets say restricted I could abstract over it by creating a new type that could be used like an int but had those properties I needed. The process I would use to do such a thing would be called an "abstracting".

提交回复
热议问题