3 ms·
> Data abstraction > Encapsulation > Polymorphism > Inheritance Note that it's the last two concepts which are specific to object oriented programming. T
by augustk 3y ago
> Data abstraction
> Encapsulation
> Polymorphism
> Inheritance
Note that it's the last two concepts which are specific to object oriented programming. The first two are already supported by non OOP languages like C and enable implementation of abstract data types. I think it's unfortunate that all concepts are often introduced in the same OOP course which may make the students believe that a class and an abstract data type is the same thing.
- Log_out_ 3y ago> Encapsulation as an idea failed spectacular again and again. What would have been valuable would have been a way to enforce layers of abstractions, with no composition or inheritance of objects on the same layer.
- ryandv 3y agoPolymorphism is not at all specific to OOP, and there are in fact different kinds of polymorphism; "generics" are pervasive in pure FP languages such as Haskell or imperative/functional languages like Rust, and are an instance of parametric polymorphism. Ad-hoc polymorphism, or "operator overloading," can also be seen in both languages as the "Eq" typeclass/trait and the equality operator `==`. It's subtype polymorphism and deeply nested inheritance structures that are maybe particular to OOP. It's also worth making a distinction between an abstract data type - a "thing" and some set of operations defined over it - and a data structure - a particular in-memory construction and set of procedures defined over it, often used to realize an abstract data type. An example being a dictionary ADT - supporting get, set, delete, etc. being realizable through different data structures; for example, a linked "association list" of (key, value) pairs vs. a hash table - with each having different performance characteristics, despite possessing the same properties as the ADT they implement.
- adrian_b 3y agoPolymorphism that is resolved at run-time, i.e. "virtual" functions is what is specific to OOP. The term "polymorphism" was first used in the documents of the language CPL (in mid sixties), the source of BCPL, where in British English it corresponded to what in the American documents of the same age, starting with McCarthy, were called overloaded operators and overloaded functions. The use of "polymorphism" mostly for the run-time polymorphism of OOP languages has appeared only a couple of decades later, with Smalltalk. "Generic", which might be a better term than both, has been popularized during the programming language contest that has lead to Ada (1979). Nowadays it is mostly used for polymorphism/overloading that is resolved at compile time, because this is how the term has been used in Ada.
- ryandv 3y agoEven still, there exist non-OOP implementations of runtime dynamic dispatch, such as Clojure's multimethods.
- ykonstant 3y agoI thought Julia's multiple dispatch was run-time polymorphism?
- mostlylurks 3y agoEven polymorphism that is resolved at run-time is not specific to OOP. In fact, it's used quite extensively outside of OOP, including in both functional and procedural programming. Even ignoring the types of dynamic polymorphism present in other paradigms that might be called "OOP-inspired", there are commonplace patterns such as the use of closures that let you achieve run-time polymorphism and data encapsulation.
- augustk 3y agoWhat you call an abstract data structure is what I have learned is called a concrete data type. To my understanding an abstract data structure is a module with global (single instance) private data which is manipulated using the module's interface. In OOP terminology it's a singleton class.
- joe_the_user 3y agoHow exactly does C support encapsulation? I mean, you can do OO type stuff with anonymous handles but the compiler will let a function take one handle type where another belongs and things will fail opaquely but immediately if you're luck and fail slowly if you're unlucky. Which is to say there is no "support".
- augustk 3y ago> How exactly does C support encapsulation? You simply declare a type as a pointer to a struct in the header file along with the functions that operate on variables of this type, and define the struct and the functions in the implementation file. M.h typedef struct M_TDesc *M_T; void M_Foo(M_T x); ... M.c #include "M.h" struct M_TDesc { ... }; void M_Foo(M_T x) { ... } ...
- kaba0 3y agoThat’s not encapsulation, that’s just an ugly hack. Somewhat related, it has been shown that a language with public/private visibility modifiers is more expressive than one without (that is, it can’t be locally replaced by another expression that results in the same program).
- augustk 3y ago> That’s not encapsulation, that’s just an ugly hack. Call it what you want but it works well. Declaring a variable or function as static corresponds to "private". I honestly don't understand what you mean by "locally replaced by another expression", I think you'll need to exemplify.
- hardlianotion 3y agoIs forward declaring available in C? Seems like it would have the same effect as declaring a pointer.