1 / 11

Presentation November 2 nd , 2009 Quoc K. Le CS 265- 001

Learn the principles of interface design and how they contribute to code organization, information hiding, and consistency. Discover how to create interfaces that are easy to understand, use, and maintain.

jtibbs
Download Presentation

Presentation November 2 nd , 2009 Quoc K. Le CS 265- 001

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Presentation November 2nd, 2009 Quoc K. Le CS 265- 001

  2. A summary of interface principles

  3. Interface • Interface is the detailed boundary between code that provides a service and code that uses it. • It defines: What some body of code does for its users, how functions can be used

  4. Generally, good interfaces must follow a set of principles: • Hide implementation details (Info hiding) • Choose a small orthogonal set of primitives • Don’t do secret stuffs. • Be consistent

  5. Hide implementation details: Other terms for this kind of organizing principle: Encapsulation, Information hiding, abstraction, modulization. Example: Classes such as string, vector, deque… It’s easy to implement them without knowing how they do

  6. It’s recommendable not to make data publicly visible. • Users might change variables.

  7. 2. Choose a small orthogonal set of primitives. • An interface should provide as much functionality as necessary but no more. • A large interface is harder to build and maintain. • It also makes users harder to learn. • Narrow interface are preferred.

  8. Example: C standard I/O library provides several ways to write a single character to an output stream: • char c; • putc(c, fp); • fputc(c, fp); Not necessary!

  9. 3. Don’t be secret • A library function should not write secret files and variables or change global data • Example: function strtok in the class string It functions to split string into tokens. However the function writes NULL bytes into the middle of its input string

  10. 4. Consistency: In other words, do the same thing the same way everywhere. Consistency makes functions easy to understand and use without much studying. Example: The loops are presented quite the same ways in several languages such as C++, Java, Perl…

More Related