The Gap Between Test and Reality (feat. OOP)
2025-05-06
I'm preparing for a certification. What certification?
I'm preparing for the "Information Processing Technician," which was a dog and pony show until the 2020 revision.
When I was taking the test, I came across the following question.
Which of the following is most closely related to information hiding in object orientation?
- Encapsulation
- Class
- Method
- Instance
The correct answer was Encapsulation, and while I got it right, I felt a twinge of recognition. The reason for the cringe is that I'm a Python developer. **In Python, encapsulation is often implemented implicitly through combinations of classes and methods without explicit access control. Because there is no access controller, encapsulation is more of a convention for implementing a limited level of hiding within the context of a class than it is a standalone concept.
So is this a double-edged sword, given Python's object orientation?
No. In Python, encapsulation has nothing to do with hiding information.
Sure, you can mimic it with `__conventions' and decorators, but you can't truly hide information because you don't have access controllers like C++/Java.
So when I saw this problem, I actually thought of Abstraction**, which is neither an encapsulation nor a class, because that's the closest thing we have to an object-oriented concept in Python.
The answer explanation for the question was
Encapsulated objects are closely related to information hiding because their details are hidden from the outside world.
This raises the question, are encapsulation and classes different concepts in C++/Java?
It turns out they are. Take Java for example
public class User {
public String name;
public int balance;
}
This is a case where a class exists, but it is not encapsulated.
public class User {
private String name;
private int balance;
public String getName() { return name; }
public int getBalance() { return balance; }
}
On the other hand, in this case, the structure is an explicit combination of class and encapsulation.
**But in Python?
class User:
def __init__(self):
self.balance = balance
This is both an encapsulation and a class. To hide information, which is the problem, we need to use the
class User:
def __init__(self, balance):
self.__balance = balance
def get_balance(self):
return self.__balance
account = User(1000)
print(account.get_balance())
for the "information hiding" in question. However, this is code for the sole purpose of hiding information, it is not perfect information hiding, and it has nothing to do with the concept of "encapsulated classes" in Java.
From that perspective, from a Python developer's point of view, this problem has virtually no answer.
If the question had a "by C++/Java" subtext, then encapsulation would undoubtedly be the correct answer. This is because encapsulation can result in information hiding.
However, in the case of Python/Ruby, the equation encapsulation = information hiding doesn't hold. Structurally, the encapsulation is there, but the information hiding itself is left to the implementer.
The more fundamental question is this. OOP is not a language-specific implementation in the first place, but a conceptual mindset that transcends languages. However, I wonder if we are defining the concept by relying on the implementation of C++/Java.
As it is essentially a national technical qualification exam, if the question was intended to assess the concept of object-orientation as a basic CS knowledge while maintaining language neutrality, it should have been a narrative question, not a biased multiple-choice option like this. Was it intended to ask about the concept, and if so, why did it have a question that could only be answered in Java and C++? Was it intended to reflect real-world practice, and if so, why did it impose explanations that do not hold true in real-world languages (Python, Ruby, Go)?
Fundamentals of Object Orientation
Alan Kay is the man who coined the term Object-Oriented Programming. And he has a famous quote
"I invented the term 'object-oriented', and I can tell you I did not have C++ in mind."
In other words, object-orientation is not a concept that was born in C++ or Java; its roots are in a language called Smalltalk, and its philosophy is as follows.
Objects have state, and interact through messages.
Encapsulation is about hiding implementation details and providing only interfaces.
Message passing and covertness are more important than classes and inheritance.
In conclusion, depending on the language, encapsulation may or may not lead to information hiding. In my main language, Python, this is not the case, but OOP does exist in Python.
Someone might ask why I'm so tired of living with a problem that is neither wrong nor right, but I think that by digging through this process, I can get "real knowledge" instead of "dead knowledge" that is not related to my language environment of "encapsulation = information hiding".
Kakao
Google
Naver