A brilliant example of effective encapsulation through information hiding?

后端 未结 5 928
旧时难觅i
旧时难觅i 2021-02-04 12:13

\"Abstraction and encapsulation are complementary concepts: abstraction focuses on the observable behavior of an object... encapsulation fo

5条回答
  •  北海茫月
    2021-02-04 13:10

    The *nix abstraction of character streams (disk files, pipes, sockets, ttys, etc.) into a single entity (the "everything is a file") model allows a wide range of tools to be applied to a wide range of data sources / sinks in a way that simply would not be possible without the encapsulation.

    Likewise, the concept of streams in various languages, abstracting over lists, arrays, files, etc.

    Also, concepts like numbers (abstracting over integers, half a dozen kinds of floats, rationals, etc.) imagine what a nightmare this would be if higher level code was given the mantissa format and so forth and left to fend for itself.

提交回复
热议问题