Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following alternative interface for the counter ADT: public interfa

ID: 3880937 • 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 at least two issues in PoorlyDesignedCounter, and describe them.

Explanation / Answer

an API may be
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)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote