質問

Is it fair to say that the following statement is not exactly correct, considering that in procedural programming you can have local scope?

"In procedural program, data is exposed to the whole program whereas in OOPs program, it is accessible with in the object and which in turn assures the security of the code."

(I'm a student and I was asked this question at an interview for an internship)

役に立ちましたか?

解決

I agree with Mark, the part that isn't exactly correct is the "assures the security of the code".

An Object Oriented language is, under the hood, doing the same thing a procedural language could be doing: hide type definitions and then pass a pointer to a struct containing data vs. using a global. An example is C's pthreads library, which uses opaque types to prevent users of the API from modifying internal data structures. (Opaque just means the struct is defined in a private header, so the user can't see inside it without pointer tricks.)

But data security? No, because you can still use pointers to peak inside opaque structs and even to inspect data on the stack. This works in C++ too. A hacker can still attempt to examine a program's memory too (debugger, core dump, other tricks).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top