Advanced Database Systems

0 of 4 lessons complete (0%)

Chapter 1: Concepts for Object-Oriented DatabasesAdvanced Database Systems

1.3. Encapsulation of Operations, Methods, and Persistence

This is a preview lesson

Register or sign in to take this lesson.

Encapsulation, Methods & Persistence – CoSc 2042 | Ethio Temari
Advanced Database Systems: Encapsulation, operations, methods, persistence – OODB. With exam tips & practice for Ethiopian students.

📦 Chapter 1.3 – Encapsulation of Operations, Methods, and Persistence

👋 Hey again, future database experts! Today we talk about encapsulation, the difference between signature and method, and what it means for objects to be persistent. Let’s make it super clear – stay with me! 🇪🇹

🧬 1.3.1 What is Encapsulation? (Information hiding)

From the PDF: “Encapsulation is one of the main characteristics of OO languages. It is related to abstract data types and information hiding.” In simple words, encapsulation means we hide the internal details of an object and only expose a clean interface. Think of a television: you use the remote (buttons) to change channel – you don’t touch the inner circuits. That’s encapsulation!

The object’s internal structure (data) is hidden; the outside world can only interact via predefined operations.

╔════════════════════════════════╗ ║ BankAccount object ║ ╠════════════════════════════════╣ ║ – hidden data: ║ ║ balance, pin, transactionLog║ ║ – visible operations: ║ ║ + deposit(amount) ║ ║ + withdraw(amount) ║ ║ + getBalance() ║ ╚════════════════════════════════╝

You cannot directly change balance; you must call deposit() or withdraw(). That’s encapsulation protecting the data.

🔍 Signature vs Method – important distinction

The PDF says: “Signature: is the interface part of each operation. Method: is implementation of the operation.”

  • Signature – name + parameters (what it looks like from outside).
  • Method – the actual code/implementation (how it does it).

Example: withdraw(amount) is the signature. The method contains the steps: check balance, deduct, log transaction, etc.

🎓 Real classroom example: When you send a message to an object (like std.withdraw(200)), the object executes the corresponding method. The caller doesn’t care how it’s implemented, only that it works. That’s encapsulation!

📝 Practice – encapsulation basics

Q1 (Mid): In OODB, the interface part of an operation (name + parameters) is called _________ .
A) Method
B) Signature
C) Constructor
D) Message

✅ B – Signature. Signature defines the operation’s name and parameters; method is the implementation.

Q2 (Exit style): Which of the following best describes encapsulation?
A) Allowing one class to inherit from another
B) Hiding internal state and requiring interaction via methods
C) Storing data in tables
D) Using OID for objects

✅ B – hiding internal state, accessible only through methods.

Q3: A method is invoked by sending a _________ to the object.
A) signature
B) message
C) constructor
D) query

✅ B – message. The object then executes the matching method.

👁️ 1.3.2 Visible vs Hidden Attributes (partial encapsulation)

The PDF mentions: “For database applications, the requirement that all objects be completely encapsulated is too stringent. So it divides the structure of an object into visible and hidden attributes.” That’s a very important point for exams.

In databases, we sometimes want to allow direct reads for some attributes (like name in a SELECT query) while keeping sensitive data hidden (like salary or password). So we make some attributes visible (accessible to external queries) and others hidden (only through methods).

Employee object ┌─────────────────────────────────┐ │ VISIBLE attributes (readable) │ │ – emp_id, name, department │ ├─────────────────────────────────┤ │ HIDDEN attributes │ │ – salary, taxInfo, loginToken │ │ only accessible via methods │ │ – getSalary() – needs auth │ └─────────────────────────────────┘

💡 Why? Because in databases, we need efficient querying (e.g., find all employees in CS department). If everything were hidden, we couldn’t run simple queries without writing methods for everything. So databases relax full encapsulation.

📌 Exam tip: They may ask: “Why do OODB systems not enforce full encapsulation?” Answer: To allow flexible querying – some attributes must be visible for direct access.

Q4 (Final): In an object‑oriented database, attributes like ‘salary’ are often hidden. How can a user read the salary?
A) Directly via SQL SELECT
B) Through a predefined method that may include security checks
C) By using the OID
D) They cannot ever access it

✅ B – via a method. Hidden attributes are accessible only through operations (methods).

Q5: Which statement is TRUE according to the PDF?
A) All attributes must be hidden
B) Attributes are divided into visible and hidden parts
C) Only methods are hidden
D) Visible attributes cannot be read by external users

✅ B. The database relaxes encapsulation: some attributes are visible, some hidden.

💾 1.3.3 Methods and Persistence

Persistence means the object lives beyond the program that created it – it’s stored in the database permanently. In OODB, both data and methods are stored together. So when you retrieve an object, you also retrieve its behaviour.

🔄 Operations on objects (from PDF):

  • Create (insert) an object
  • Destroy (delete) an object
  • Update object state
  • Retrieve parts of the object state

These are all done by sending messages to the object, which invokes the corresponding method.

🌍 Example – persistent Student object:

// Create a new student object
Student s = new Student("Abebech", "CS");
s.save();   // now persistent in OODB

// Later, retrieve and update
Student s2 = database.lookup(oid1023);
s2.enroll("Advanced DB");   // method call
    

The methods save(), lookup(), enroll() are part of the object’s definition stored in the database.

📋 Why store methods together with data?

  • Behaviour is consistent across all applications.
  • Easier to maintain – change method once in the database.
  • Complex objects can include domain logic.

Q6 (Exit): In an object‑oriented database, persistence means:
A) The object lives only while program runs
B) The object is stored permanently and can be accessed later
C) Only the data is stored, methods are lost
D) The OID changes after storing

✅ B – permanently stored. Persistent objects survive program termination.

Q7 (Mid): Which of the following is NOT an operation mentioned for objects?
A) Create
B) Destroy
C) Compile
D) Update

✅ C – Compile. Compile is not an object operation; we have create, destroy, update, retrieve.

🧠 1.3.4 Putting encapsulation & persistence together

Encapsulation ensures that objects are used correctly via methods; persistence makes them live forever in the database. Together they form the backbone of OODB.

🎯 Exam tips – encapsulation & persistence

  • Be ready to differentiate signature vs method (signature is the “what”, method is the “how”).
  • Explain why databases allow visible attributes – to support ad‑hoc queries.
  • Define persistence – objects stored permanently, outliving the program.
  • Remember that methods are stored with data in OODB.

📝 More practice – mixed (exit level)

Q8: In an OODB, what is the main reason to split attributes into visible and hidden?
A) To increase encapsulation
B) To allow efficient querying while still protecting sensitive data
C) To reduce storage space
D) To make OIDs unnecessary

✅ B – allow query flexibility + data protection. Complete encapsulation would prevent simple queries.

Q9 (true/false): In a fully encapsulated OODB, all attributes are hidden and can only be accessed via methods. (True/False) – but database systems often relax this. So the statement is true for “pure” OO, but false for practical OODB? Wait, the PDF says full encapsulation is too stringent. So they relax it. In an exam, they may ask: “Is full encapsulation used in OODB?” → No, because visible attributes are allowed.

✅ The statement is FALSE for practical OODB – they use visible attributes. Pure OOP requires full encapsulation, but databases relax it.

Q10: A method is invoked by sending a _________ to the object.
A) message
B) query
C) signature
D) OID

✅ A – message. Message triggers method execution.

📊 Quick comparison table

ConceptDefinitionExample
EncapsulationHiding internal state, access via methodsbalance hidden, deposit() method
SignatureName + parameters of an operationwithdraw(amount)
MethodImplementation code of operationif(balance>=amount){ balance-=amount; }
Visible attributeCan be read directly (without method)employee name
Hidden attributeAccessible only via methodssalary, pin
PersistenceObject stored permanently in DBdatabase.save(student)

✨ Chapter 1.3 – key takeaways

  • Encapsulation hides data, exposes operations (signatures).
  • Signature is interface, method is implementation.
  • OODB relaxes full encapsulation: visible + hidden attributes.
  • Persistence = objects stored permanently (data + methods).
  • Operations: create, destroy, update, retrieve.

📚 Keep studying – you’re doing great! Tell your classmates about ethiotemari.com for more free lessons.

Scroll to Top