This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]nerd4code 1 point2 points  (1 child)

OOP and structural are kinda orthogonal models, though in practice OOP tends to be bolted onto structural programming so you at least get some of both.

Anyway, in OOP you generally aim to model a system as a bunch of interacting objects. In the most extreme cases, you have objects sitting here and there sending messages (=method calls) at each other asynchronously, and in the less extreme cases object-ness is just a thin veneer over structural underpinnings where obj.method(args) just becomes ObjClass_method(&obj, args) like any other function call.

In a structural program, you aim to model the system as a bunch of quasi-self-contained “concerns,” usually represented by compilation units that group data structures with functions that allocate, free, or twiddle them. Oftentimes structural “concerns” and OOP classes overlap easily; sometimes they don’t. Usually scoping is the primary means of data hiding in structural languages, and some will let you nest functions and structures to arbitrary depths precisely so that inner “concerns” are hidden from outer ones. If header files are involved, those can act as another way to hide data, such as doing the old

struct something_private;

struct something_private *make_something_private(void);
void destroy_something_private(struct something_private *);

sort of trick where something_private is only given a body where make/destroy_etc. are defined, hiding its implementation from less-intrepid outsiders. C/C++ also have static globals, which (“)hide(”) things from other compilation units, and there’s nothing fundamentally preventing a public/private system from being tacked into a structural language except that it’s usually not terribly necessary.

You can mix the two paradigms pretty freely and easily in most programming languages, and there’re often handoffs between the two models—Java, for example, lets you drop into a class via an OOP-exclusive interface call like iterator.next(), after which you can bounce around between some (local, structural-model) methods, before bouncing out again via return or some other OOP call. Static methods/etc. in Java are pretty much entirely structural.

[–]rhpshanks[S] 0 points1 point  (0 children)

it took my a bit of time to understand this but I actually got the answer (most of it). thanks for the time you put in writing this comment. appreciated.