CS FundamentalsHardWipro · Cognizant technical pattern
A method in class Invoice spends most of its code reading fields of a Customer object (name, address, discount tier) and barely uses Invoice’s own data. Which code smell is this, and what is the usual refactoring?
- A. God class — split Invoice into many classes
- B. Feature envy — move the method (or that part of it) into Customer
- C. Shotgun surgery — merge Invoice and Customer
- D. Primitive obsession — replace the fields with strings
Correct answer: B. Feature envy — move the method (or that part of it) into Customer
A method more interested in another class’s data than its own shows feature envy; moving it next to the data improves cohesion and reduces coupling. Shotgun surgery is when one change needs edits in many classes; a god class does too much overall.
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
- Tasks and durations (days): A 3; B 4 (after A); C 2 (after A); D 5 (after B and C); E 1 (after C). What is the total slack (float) of task…
- A form has 3 parameters — browser (3 options), OS (3 options) and language (3 options). Exhaustive testing needs 27 combinations. What is…
- A new app version is first served to 5% of users while error rates and latency are watched; if the metrics stay healthy, the share is…
- According to Semantic Versioning precedence rules, which list is in correct ascending order?
- Counting every simple condition of a compound boolean expression as a separate decision (each && / || adds one), what is the cyclomatic…
- What is the cyclomatic complexity of this fragment? Count each case label other than default as one decision and each simple condition…