author | Jaroslav Tulach <jtulach@netbeans.org> |
Thu, 27 Oct 2011 21:22:26 +0200 | |
changeset 385 | 91c9416df025 |
permissions | -rw-r--r-- |
jtulach@385 | 1 |
package org.apidesign.samples; |
jtulach@385 | 2 |
|
jtulach@385 | 3 |
/** Showing some horrible usages of singletons. |
jtulach@385 | 4 |
*/ |
jtulach@385 | 5 |
public class Singletons { |
jtulach@385 | 6 |
static { |
jtulach@385 | 7 |
// BEGIN: singleton.no.no |
jtulach@385 | 8 |
/** initialize singletons */ |
jtulach@385 | 9 |
Database.init(); |
jtulach@385 | 10 |
OfflineQueue.init(); |
jtulach@385 | 11 |
CreditCardProcessor.init(); |
jtulach@385 | 12 |
/** use singletons */ |
jtulach@385 | 13 |
CreditCard c = new CreditCard( |
jtulach@385 | 14 |
"1234 5678 9012 3456", 5, 2008 |
jtulach@385 | 15 |
); |
jtulach@385 | 16 |
c.charge(100); |
jtulach@385 | 17 |
// END: singleton.no.no |
jtulach@385 | 18 |
} |
jtulach@385 | 19 |
|
jtulach@385 | 20 |
static final class Database { |
jtulach@385 | 21 |
public static void init() { |
jtulach@385 | 22 |
} |
jtulach@385 | 23 |
} |
jtulach@385 | 24 |
|
jtulach@385 | 25 |
static final class OfflineQueue { |
jtulach@385 | 26 |
public static void init() { |
jtulach@385 | 27 |
} |
jtulach@385 | 28 |
} |
jtulach@385 | 29 |
|
jtulach@385 | 30 |
static final class CreditCardProcessor { |
jtulach@385 | 31 |
public static void init() { |
jtulach@385 | 32 |
} |
jtulach@385 | 33 |
} |
jtulach@385 | 34 |
|
jtulach@385 | 35 |
private static class CreditCard { |
jtulach@385 | 36 |
|
jtulach@385 | 37 |
public CreditCard(String card, int month, int year) { |
jtulach@385 | 38 |
} |
jtulach@385 | 39 |
|
jtulach@385 | 40 |
private void charge(int amount) { |
jtulach@385 | 41 |
} |
jtulach@385 | 42 |
} |
jtulach@385 | 43 |
} |