SE2 (LAB) Week 3 – 4 Strategy Pattern
Quiz
•
Computers
•
University
•
Medium
Hangaan, T.
Used 5+ times
FREE Resource
23 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Your task is to refactor this code using the Strategy pattern. All classes and methods have been made public for clarity. Which of the following approaches represents the BEST implementation?
No changes are needed, the current code with conditional statements already effectively implements the Strategy pattern.
Create a public enum GradingMethod and use a switch statement in calculateGrade to choose the appropriate calculation based on the enum value. Implement specific logic within each case of the switch statement.
Modify the calculateGrade method to accept a public interface GradingStrategy as an argument and delegate the calculation logic to it. Implement separate concrete strategy classes (e.g., AverageGradingStrategy, WeightedGradingStrategy) that extend the interface.
Replace the calculateGrade method with separate public methods for each grading method (e.g., calculateAverageGrade, calculateWeightedGrade). Each method would contain the specific calculation logic.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
You're developing a shopping cart application. You want to offer different discount calculations based on user type (e.g., standard discount, bulk discount, loyalty discount). Which approach would you use?
It depends on whether you want a fixed discount based on user type or one that changes dynamically based on cart contents.
Define different states for the cart (e.g., active, checkout, complete) and associate different discount calculations with each state.
Create separate implementations for each discount type (e.g., StandardDiscount, BulkDiscount, LoyaltyDiscount) and dynamically choose the appropriate strategy based on the user.
Build a composite discount object by combining different basic discount objects (e.g., PercentageDiscount, FlatFeeDiscount) based on user eligibility.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Imagine you're building a music player that supports different playback modes (shuffle, repeat, repeat one). Currently, your code tightly couples the playback logic directly within the MusicPlayer class. You want to improve modularity and flexibility. Which pattern can achieve this by decoupling the playback logic?
Define states for different playback modes and transition logic between them in the MusicPlayer class.
Create a single instance of a "PlaybackManager" class responsible for all playback modes
None of these choices. Tightly coupled code is necessary for playback modes.
Implement separate concrete strategies for each playback mode, allowing flexible switching within the MusicPlayer.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
You're designing a complex system with numerous interrelated components involved in processing orders. You want to simplify user interaction and improve code maintainability. Should you use the Strategy or Facade pattern?
Both Strategy and Facade patterns would achieve the same outcome, so the choice boils down to personal preference.
Use the Facade pattern to create a single entry point for order processing, hiding the complexity of interacting with all the individual components behind a simplified interface.
Use the Strategy pattern to define different order processing algorithms (e.g., express, standard, bulk) and dynamically switch between them based on customer needs.
It's impossible to know without seeing the specific code structure.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What distinguishes the Factory pattern from the Strategy pattern?
The Strategy pattern requires more complex interfaces and classes compared to the Factory pattern.
The Factory pattern is always superior to the Strategy pattern for creating different types.
The Factory pattern focuses on object creation, while the Strategy pattern deals with object behavior.
Both patterns achieve the same outcome, so the choice comes down to personal preference.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
You're building a content management system (CMS) with different publishing workflows based on content type (blog post, news article, product page). Currently, your code handles each workflow directly within the individual content type classes. To improve flexibility and maintainability, you're considering design patterns. Which pattern best suits this scenario?
Create specific implementations of each publishing workflow, enabling dynamic switching based on content type within the CMS.
Define states for different stages of the publishing workflow (draft, review, published) and transition logic between them within each content type class.
Create distinct factories for each content type, responsible for generating objects with the appropriate publishing workflow logic embedded.
All of these approaches could be beneficial for this scenario.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
public interface PublishingWorkflowStrategy {
public void ___Q1___ (Content content);
}
publish
PublishingWorkflowStrategy
content
Create a free account and access millions of resources
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?
Similar Resources on Wayground
20 questions
LLB10403 Quiz 2 Chap 2
Quiz
•
University
20 questions
AWD - Prelim Quiz
Quiz
•
University
20 questions
CompTIA Sec+
Quiz
•
University - Professi...
18 questions
Sorting Algorithms II
Quiz
•
University
20 questions
CSE493_QUIZ 1
Quiz
•
University
20 questions
Dampak sosial informatika
Quiz
•
11th Grade - University
20 questions
HOJAS DE ESTILO
Quiz
•
University
20 questions
HTML
Quiz
•
KG - University
Popular Resources on Wayground
20 questions
Halloween Trivia
Quiz
•
6th - 8th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
15 questions
Order of Operations
Quiz
•
5th Grade
20 questions
Halloween
Quiz
•
5th Grade
16 questions
Halloween
Quiz
•
3rd Grade
12 questions
It's The Great Pumpkin Charlie Brown
Quiz
•
1st - 5th Grade
20 questions
Possessive Nouns
Quiz
•
5th Grade
10 questions
Halloween Traditions and Origins
Interactive video
•
5th - 10th Grade
Discover more resources for Computers
10 questions
Halloween Movies Trivia
Quiz
•
5th Grade - University
12 questions
Halloween
Quiz
•
3rd Grade - University
5 questions
Using Context Clues
Interactive video
•
4th Grade - University
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)
Quiz
•
8th Grade - University
7 questions
Force and Motion
Interactive video
•
4th Grade - University
14 questions
Eat Healthy,Be Healty
Quiz
•
4th Grade - University
7 questions
History of Halloween: Pagan or Christian?
Interactive video
•
11th Grade - University
7 questions
Renewable and Nonrenewable Resources
Interactive video
•
4th Grade - University
