How could we experience the power of object oriented programming in procedural language? [closed]
-
12-12-2019 - |
Question
As we know that the Object oriented programming language has lots of benefit.But in same implementation procedural language like C do not have any alternative like realtime applications. So can we combine the power of two to create a great application? Can we experience the major pillars of OOPS in procedural language?
Solution
Nearly all general-purpose languages are Turing equivalent. This means -- among other thing -- that anything you can dream up in one language, you can implement in another. So yes, it's possible, though it isn't enforced by the compiler as strictly as an OOP zealot might like.
Consider C's FILE
type (used by fopen
, fread
, fwrite
, etc). It's not specified what exactly is in there, and you don't need to know or care (read: encapsulation); all you have to know is, you can fopen
you a file, fread
/fwrite
it, and when you're done, you fclose
. Thing is, that "file" can be anywhere -- at the root of the FS, in your homedir that's on a whole other drive...in most OSes, it can even be a pipe or a network socket (read: polymorphism).
Basically, the funnest parts of OOP. And we didn't say "class" even once. :)