Add Frobber to the list of available widgets. This allows consumers to easily discover the new Frobber widget and add it to their application.
class Mammal { ... virtual Status Sleep(bool hibernate) = 0; }; class Human : public Mammal { ... virtual Status Sleep(bool hibernate) { age += hibernate ? kSevenMonths : kSevenHours; return OK; } };
class Human { ... void Sleep() { age += kSevenHours; } };
// Subtract discount from price. finalPrice = (numItems * itemPrice) - min(5, numItems) * itemPrice * 0.1;
price = numItems * itemPrice; discount = min(5, numItems) * itemPrice * 0.1; finalPrice = price - discount;
// Filter offensive words. for (String word : words) { ... }
filterOffensiveWords(words);
int width = ...; // Width in pixels.
int widthInPixels = ...;
// Safe since height is always > 0. return width / height;
checkArgument(height > 0); return width / height;
// Compute once because it’s expensive.
// Create a new Foo instance because Foo is not thread-safe.
// Note that order matters because...
@SuppressWarnings("unchecked") // The cast is safe because...
// Get all users. userService.getAllUsers();
// Check if the name is empty. if (name.isEmpty()) { ... }