0
0
Software Engineeringknowledge~20 mins

Creational patterns (Singleton, Factory, Builder) in Software Engineering - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Creational Patterns Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Singleton Pattern Behavior

What is the main purpose of the Singleton pattern in software design?

ATo ensure a class has only one instance and provide a global point of access to it.
BTo create objects without specifying the exact class of object to create.
CTo separate the construction of a complex object from its representation.
DTo allow multiple instances of a class with different configurations.
Attempts:
2 left
💡 Hint

Think about controlling the number of instances of a class.

📋 Factual
intermediate
2:00remaining
Factory Pattern Purpose

Which statement best describes the Factory pattern?

AIt provides an interface for creating objects but lets subclasses decide which class to instantiate.
BIt ensures only one instance of a class exists throughout the application.
CIt builds complex objects step by step, allowing different representations.
DIt allows an object to alter its behavior when its internal state changes.
Attempts:
2 left
💡 Hint

Focus on object creation and subclass responsibility.

🔍 Analysis
advanced
2:00remaining
Builder Pattern Application

Given a scenario where you need to create different types of complex documents with many optional parts, which creational pattern is most suitable?

AFactory, because it decides which document subclass to instantiate.
BBuilder, because it constructs complex objects step by step allowing different representations.
CSingleton, because it controls the number of document instances.
DPrototype, because it clones existing document instances.
Attempts:
2 left
💡 Hint

Think about building complex objects with many optional parts.

Comparison
advanced
2:00remaining
Comparing Singleton and Factory Patterns

Which of the following correctly contrasts the Singleton and Factory patterns?

ASingleton creates multiple objects; Factory restricts to one instance.
BSingleton and Factory both ensure only one instance exists.
CSingleton builds complex objects stepwise; Factory provides global access.
DSingleton controls instance count; Factory controls object creation type.
Attempts:
2 left
💡 Hint

Focus on what each pattern controls or manages.

Reasoning
expert
2:00remaining
Singleton Pattern Thread Safety Challenge

Consider a Singleton implementation in a multi-threaded environment. What is the main risk if the Singleton is not implemented with thread safety?

AThe Singleton will automatically become a Factory, creating different objects.
BThe Singleton instance will never be created, causing null reference errors.
CMultiple instances of the Singleton class may be created, breaking the pattern's intent.
DThe Singleton instance will be shared safely without any issues.
Attempts:
2 left
💡 Hint

Think about what happens when two threads try to create the instance at the same time.