Question 316 of 481
1Z0-811 Object-Oriented Programming Practice Question
A developer is working on a Java application that processes sensor data. The code uses a class 'SensorDataProcessor' which directly instantiates specific sensor classes like 'TemperatureSensor' and 'PressureSensor' inside its methods. The team wants to make the system extensible to support new sensor types without modifying the processor class. Which design change best achieves this?
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
✓
Define a Sensor interface and use dependency injection to pass sensor objects to the processor
Defining a Sensor interface and using dependency injection (e.g., passing sensor objects via constructor or setter) decouples the processor from concrete sensor classes, allowing new sensor types to be added without modifying the processor. Option A is wrong because creating subclasses for each sensor would still require modifying the processor if new sensor types are added. Option B is wrong because a static factory method still couples the processor to the factory and requires changes when new sensors are added. Option C is wrong because reflection is complex, error-prone, and not the best practice for this scenario.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Make SensorDataProcessor abstract and subclass it for each sensor
Why it's wrong here
This still requires a new subclass of the processor for each sensor type.
- ✗
Use a static factory method in SensorDataProcessor to create sensors
Why it's wrong here
The processor remains coupled to the factory, which must be updated for new sensors.
- ✗
Create a separate configuration file listing sensors and use reflection to instantiate them
Why it's wrong here
Reflection is error-prone and performance-heavy; dependency injection is cleaner.
- ✓
Define a Sensor interface and use dependency injection to pass sensor objects to the processor
Why this is correct
Dependency injection allows the processor to work with any Sensor implementation.
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 →
Last reviewed: Jun 23, 2026
This 1Z0-811 practice question is part of Courseiva's free Oracle 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 1Z0-811 exam.
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.
Sign in to join the discussion.