User Interface Principles in API Design Elliotte Rusty Harold

Slides:



Advertisements
Similar presentations
Basic -2 Classes and Objects. Classes and Objects A class is a complex data TYPE An object is an instance of a class. Example: Class: Person Objects:
Advertisements

COM vs. CORBA.
What is MVC? At the very least it’s just another computer acronym…Model-View-Controller It might be new to you but it’s been around for 30 years In varying.
Mutability SWE 332 Fall 2011 Paul Ammann. SWE 3322 Data Abstraction Operation Categories Creators Create objects of a data abstraction Producers Create.
Software Construction 1 ( ) First Semester Dr. Samer Odeh Hanna (PhD) Office: IT 327.
Inheritance Polymorphism Briana B. Morrison CSE 1302C Spring 2010.
Liang,Introduction to Java Programming,revised by Dai-kaiyu 1 Chapter 10 Object-Oriented Modeling.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
Feb. 23, 2004CS WPI1 CS 509 Design of Software Systems Lecture #5 Monday, Feb. 23, 2004.
Chapter 1 Principles of Programming and Software Engineering.
Chapter 10 Classes Continued
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Systems Analysis and Design in a Changing World, Fifth Edition
C++ Programming. Table of Contents History What is C++? Development of C++ Standardized C++ What are the features of C++? What is Object Orientation?
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
Chapter 8 More Object Concepts
CISC6795: Spring Object-Oriented Programming: Polymorphism.
Software Construction Lecture 10 Frameworks
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 11 : Frameworks SWE 316: Software Design and Architecture  To understand.
07 Coding Conventions. 2 Demonstrate Developing Local Variables Describe Separating Public and Private Members during Declaration Explore Using System.exit.
Slide 1 Construction (Testing) Chapter 15 Alan Dennis, Barbara Wixom, and David Tegarden John Wiley & Sons, Inc. Slides by Fred Niederman Edited by Solomon.
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
Defining New Types Lecture 21 Hartmut Kaiser
SE: CHAPTER 7 Writing The Program
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Systems Analysis and Design in a Changing World, 3rd Edition
Best Practices. Contents Bad Practices Good Practices.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
Requirement Handling
Frameworks CompSci 230 S Software Construction.
Introducing Allors Applications, Tools & Platform.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Introduction to Software Architecture.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
User Interface Principles in API Design Elliotte Rusty Harold
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 11 Object-Oriented.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Lecture Videos will no longer be posted. Assignment 3 is due Sunday, the 8 th, 7pm. Today: –System Design,
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Exceptions Lecture 11 COMP 401, Fall /25/2014.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc. All rights.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
619 Final Review Last updated Fall 2011 Paul Ammann.
CSE 2341 Object Oriented Programming with C++ Note Set #4
11 Systems Analysis and Design in a Changing World, Fifth Edition.
SE-1021 Software Engineering II
CSE687 - Object Oriented Design class notes Survey of the C++ Programming Language Jim Fawcett Spring 2004.
Chapter 11 Object-Oriented Design
Principles of Programming and Software Engineering
About the Presentations
Magento Technical Guidelines Eugene Shakhsuvarov, Software Magento
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Object-Oriented Programming
Object Based Programming
Software Testing and Maintenance Modifying Code
More Object-Oriented Programming
Object Oriented Practices
619 Final Review Last updated Spring 2010 © : Paul Ammann.
Inheritance Lakshmish Ramaswamy.
Presentation transcript:

User Interface Principles in API Design Elliotte Rusty Harold

“API usability is the intersection of user-centered design and excellent coding practices” --David Koelle & Geertjan Wielenga

Programmers Are People Too Eat Like Humans Sleep Like Humans Mate Like Humans Think Like Humans

User Interface Design is a Science Based on hypothesis, observation and experiment Well-proven, well-tested theories

Fundamental Principles Consistency is next to godliness Simpler is better Visible complexity is bad Smaller equals easier to use

Libraries vs. Applications Applications are monolithic Only other programmers on the same team use an application’s API Libraries can make very limited assumptions about how, when, where, and why API will be invoked Boundary is fuzzy

Remember the People Why you need an API Who uses the API Who designs the API

Be User Focused Ask what the user wants to do with your API Do not ask what the internal data structures and algorithms look like High level API is better than lower level-- Reduce the number of method calls needed to accomplish the task Design from the outside in Start with the end in mind

What to put in an API Write sample programs first; Sample-first programming 80/20 rule Maximal vs. Minimal APIs YAGNI When in doubt, leave it out! Why I’m a conservative

Dependencies Platform version Library dependencies Built-in vs. 3rd party libraries

Data Encapsulation Public vs. Published Fields are private Methods are mostly private Methods are atomic Constructors and destructors Communicating with the user

Constraints APIs must enforce domain validity Preconditions Postconditions Class invariants System invariants Construct complete objects only (Builder pattern)

Error Handling Specify what happens on bad input as well as good Important for security No undefined behavior Don’t silently swallow exceptions Error messages should be verbose but clear Don’t warn the user

Naming Conventions Review naming conventions Use standard terminology Do not abbreviate Use domain specific vocabulary Consistent terminology: always use the same word for the same idea –e.g. add vs. append Do not use two words for one idea

Avoid Complexity Prefer classes to interfaces Prefer constructors to factory methods Avoid excessive abstraction You usually don’t need multiple implementations Refactor to patterns; don’t start with them. Avoid pattern overload!

Inheritance Prefer finality –(at least on methods) Factories and interfaces The proper use of protected

Plays well with others (Java): Serializable Cloneable(*) Comparable equals() hashCode() toString() Exception handling Thread safety

Plays well with others (.NET): Equals() / GetHashCode() ToString() IEquatable / IComparable “Collection” suffix for IEnumerable classes Icloneable* Override ==, etc. for value types (only) No pointer arguments to public methods Don’t throw exceptions from overloaded operators and implicit casts

Testability The API itself Client code that uses the API This is a secondary concern

Documentation Specification Quick Start Tutorials Example code API Documentation Per method checklist

Conformance Testing Specifications Test Suites Implementation dependent behavior Implementation dependent extensions

Maintenance Planning for the future Forwards compatibility Backwards compatibility Unexpected limits Deprecation Breaking compatibility Interfaces vs. classes

The Last Concern (Performance) Speed Size Energy

Case Study: JMidi vs. JFugue

JMidi: Play Middle-C Sequencer sequencer = MidiSystem.getSequencer(); Sequence sequence = sequencer.getSequence(); Track track = sequence.createTrack(); ShortMessage onMessage = new ShortMessage(); onMessage.setMessage(ShortMessage.NOTE_ON, 0, 60, 128); MidiEvent noteOnEvent = new MidiEvent(onMessage, 0); track.add(noteOnEvent); ShortMessage offMessage = new ShortMessage(); offMessage.setMessage(ShortMessage.NOTE_OFF, 0, 60, 128); MidiEvent noteOffEvent = new MidiEvent(offMessage, 200); track.add(noteOffEvent); sequencer.start(); try { Thread.sleep(track.ticks()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } // courtesy of David Koelle

JMidi: Play Middle C Player player = new Player(); player.play("C"); // Play first 2 measures (and a bit) of “Für Elise” player.play("E6s D#6s | E6s D#6s E6s B5s D6s C6s | A5i."); // courtesy David Koelle

Lessons Learned Domain Specific Language –Takes advantage of domain specific knowledge –Easier to write; easier to read –Java is not the right notation for all use cases (nor is XML, nor Ruby, nor JSON, nor SQL, nor…) Focus on what the client wants to do; not how the software does it Avoid Abstract Factory; don’t catch “patternitis”

Case Study: BoxLayout vs. GridBagLayout

Gridbag Calculator

BoxLayout Calculator

Lessons Learned Follow naming conventions Focus on what the user wants to do; not the internal data model and algorithms

Further Reading Effective Java: Joshua Bloch Effective C#: Bill Wagner Framework Design Guidelines: Krzysztof Cwalina, Brad Abrams Tog on Interface: Bruce Tognazzini GUI Bloopers: Jeff Johnson