Question 138 of 511
Object-Oriented ProgrammingmediumMultiple ChoiceObjective-mapped

Quick Answer

The answer is the Decorator pattern, because it allows you to add new behavior—like logging—to an existing object without altering its class or breaking the Open/Closed Principle. In this scenario, a LoggingProcessor wraps a concrete DataProcessor, logs the data, and then delegates to the wrapped object’s process method, reusing the original logic seamlessly. On the PCAP exam, this tests your understanding of structural design patterns and the principle of composition over inheritance; a common trap is confusing the Decorator with inheritance-based subclassing, which would require modifying every processor. Remember the mnemonic "Wrap and Delegate"—the Decorator wraps an object and delegates the core work to it, adding its own behavior before or after.

PCAP Object-Oriented Programming Practice Question

This PCAP practice question tests your understanding of object-oriented programming. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

A team is developing a data processing pipeline where each step is a class that implements a common interface. They have defined an abstract base class DataProcessor with an abstract method process(data). Several concrete subclasses implement process. Now they need to add a new step that logs the data before processing. They want to reuse the existing processing logic without modifying the original classes. Which design pattern should they apply?

Question 1mediummultiple choice
Read the full NAT/PAT explanation →

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Decorator pattern by creating a LoggingProcessor subclass that wraps another processor and calls its process method after logging.

The Decorator pattern allows behavior to be added to an individual object, either statically or dynamically, without affecting the behavior of other objects from the same class. By creating a LoggingProcessor that wraps an existing DataProcessor and delegates to its process method after logging, the team reuses the original processing logic without modifying the existing classes, adhering to the Open/Closed Principle.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Factory pattern to instantiate processors dynamically.

    Why it's wrong here

    Factory pattern is about object creation, not adding behavior.

  • Decorator pattern by creating a LoggingProcessor subclass that wraps another processor and calls its process method after logging.

    Why this is correct

    Decorator pattern adds responsibility dynamically without modifying the original class.

    Related concept

    Read the scenario before looking for a memorised answer.

  • Singleton pattern to ensure only one logger exists.

    Why it's wrong here

    Singleton controls instantiation, not behavior extension.

  • Observer pattern to notify loggers of data changes.

    Why it's wrong here

    Observer pattern is for one-to-many dependency, not for wrapping.

Common exam traps

Common exam trap: answer the scenario, not the keyword

Python Institute often tests the Decorator pattern in scenarios where the requirement is to add responsibilities to objects dynamically without altering their structure, and the trap is that candidates confuse it with the Factory pattern because both involve creating objects, but the Decorator focuses on extending behavior, not on instantiation logic.

Detailed technical explanation

How to think about this question

In Python, the Decorator pattern is often implemented using a wrapper class that implements the same interface as the component it decorates, storing a reference to the component and adding behavior before or after delegating to it. This pattern is a structural design pattern that promotes composition over inheritance, allowing multiple decorators to be stacked (e.g., logging, then validation) without creating a combinatorial explosion of subclasses. A real-world scenario is a middleware pipeline in a web framework like Django, where each middleware wraps the request/response handling to add cross-cutting concerns such as logging, authentication, or compression.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A media company stores terabytes of video archives that are accessed once a year for audit purposes. Moving these objects to a cold storage tier (Azure Archive, S3 Glacier, or Google Nearline) costs a fraction of hot storage. Questions like this test whether you understand storage tiers, access frequency tradeoffs, and retrieval latency requirements.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related PCAP practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free PCAP practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this PCAP question test?

Object-Oriented Programming — This question tests Object-Oriented Programming — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: Decorator pattern by creating a LoggingProcessor subclass that wraps another processor and calls its process method after logging. — The Decorator pattern allows behavior to be added to an individual object, either statically or dynamically, without affecting the behavior of other objects from the same class. By creating a LoggingProcessor that wraps an existing DataProcessor and delegates to its process method after logging, the team reuses the original processing logic without modifying the existing classes, adhering to the Open/Closed Principle.

What should I do if I get this PCAP question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Keep practising

More PCAP practice questions

Last reviewed: Jun 30, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.