Consider the following alternative interface for the counter ADT: public interfa
ID: 3784599 • Letter: C
Question
Consider the following alternative interface for the counter ADT:
public interface PoorlyDesignedCounter {
//Sets the value of the counter to the parameter.
void setCounter(int counter);
//Increments the counter by one.
void increment();
//Increments the counter by 42.
void increment42();
//Returns the number of increments since creation.
int tally();
//Returns an array of all values returned by tally.
int tallyHistory();
//Returns a string representation that counts number of increments and the ID of the counter.
String toString();
}
Sedgewick and Wayne discuss 7 basic ways an API may be poorly designed (p97; online). For example, an API may be:
1."Too hard to implement, making it difficult or impossible to develop."
2."Too hard to use, leading to complicated client code."
3."Too narrow, omitting methods that clients need."
4."Too wide, including a large number of methods not needed by any client."
5."Too general, providing no useful abstractions."
6."Too specific, providing an abstraction so diffuse as to be useless."
7."Too dependent on a particular representation, therefore not freeing client code from the details of the representation."
Review PoorlyDesignedCounter for any of these issues. Identify any issues in PoorlyDesignedCounter, and describe them. (There are multiple correct analyses - any with a correct explanation will receive credit).
Explanation / Answer
"Too narrow, omitting methods that clients need."
This is majo issue here as there is no way to access counter value.
Also instead of increment42 can be generalise with increment(int i)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.