Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2. (20 points) For each of the following code sketches answer the following: i. ii. iii. Does the code represent a violation of the principle
2. (20 points) For each of the following code sketches answer the following: i. ii. iii. Does the code represent a violation of the principle of abstraction or information hiding (pick the most significant)? What is the negative impact of the violated principle? Assume the code is part of a larger project. Suggest how it could be refactored to fix the violated principle, but still provide the same features. a) public class IndexedElementContainer extends Element { public Vector children = new Vector(); // ... public void addChildAt(Element child, int index) { children.add(index, child); } public Element getChildAt(int index) { return children.elementAt(index); } // ... } b) public class FileReader { /** Opens a file for reading * @param filePath path of the file to open * Oparam buff will be used to buffer file I/O, pass null for no buffering * @param crypto will be used to decrypt the file, pass null for no encryption * @param compress will be used to decompress the file, pass null for no compression * @return 1 on success, on failure */ public int openFile(String filePath, Buffer buff, Decryptor crypto, Decompressor compress) { } public String readLine() { // ... } public void closeFile() { } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started