CS FundamentalsHardProduct-company design interview
Match each code smell with the refactoring that usually fixes it. P: a method takes 9 parameters, several of which always travel together. Q: a switch on employee type is repeated in several methods. R: a 120-line method mixes validation, calculation and formatting. S: a class only forwards every call to another class.
- A. P-Introduce Parameter Object, Q-Replace Conditional with Polymorphism, R-Extract Method, S-Remove Middle Man
- B. P-Extract Method, Q-Introduce Parameter Object, R-Remove Middle Man, S-Replace Conditional with Polymorphism
- C. P-Remove Middle Man, Q-Extract Method, R-Introduce Parameter Object, S-Replace Conditional with Polymorphism
- D. P-Introduce Parameter Object, Q-Extract Method, R-Replace Conditional with Polymorphism, S-Remove Middle Man
Correct answer: A. P-Introduce Parameter Object, Q-Replace Conditional with Polymorphism, R-Extract Method, S-Remove Middle Man
Data clumps become a parameter object; repeated type switches become polymorphic subclasses; long methods are split with Extract Method; pure delegators are removed so callers talk to the real object.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- Using the Chidamber-Kemerer metric CBO (coupling between objects: the number of other classes a class is coupled to, counting both classes…
- Class Cart has 5 methods. Together they call 9 methods of other classes, of which 7 are distinct. What is its Response For a Class (RFC) =…
- A class has four methods with cyclomatic complexities 1, 3, 2 and 4. Using the CK metric Weighted Methods per Class (WMC) with cyclomatic…
- David Parnas's information-hiding principle says how a system should be divided into modules. Which statement captures it?
- Match each system with its architectural style. P: a compiler with lexer → parser → optimiser → code generator. Q: a typical 3-tier web…
- In MVVM, unlike MVC and MVP, how does the view usually get updated when data changes?