The common Java wisdom, perhaps wisdom is the wrong term, is to implement constant values as static final
fields. This approach makes sense for “constants” that are guaranteed to be stable. For example the class
Boolean implements two static final fields called TRUE and FALSE which represents the two instances of
that class. It would also make sense for a DAYS_IN_A_WEEK constant whose value probably is never
going to change5.
However, many so-called business “constants” change over time because the business rule changes.
Consider the following example: The Archon Bank of Cardassia (ABC) has always insisted that an account
has a minimum balance of $500 if it is to earn interest. To implement this, we could add a static field named
MINIMUM_BALANCE to the class Account that would be used in the member functions that calculate
interest. Although this would work, it isn’t flexible. What happens if the business rules change and
different kinds of accounts have different minimum balances, perhaps $500 for savings accounts but only
$200 for checking accounts? What would happen if the business rule were to change to a $500 minimum
balance in the first year, $400 in the second, $300 in the third, and so on? Perhaps the rule will be changed
to $500 in the summer but only $250 in the winter?6 Perhaps a combination of all of these rules will need to
be implemented in the future.
The point to be made is that implementing constants as fields isn’t flexible, a much better solution is to
implement constants as getter member functions. In our example above, a static (class) member function
called getMinimumBalance() is far more flexible than a static field called MINIMUM_BALANCE because we
can implement the various business rules in this member function and subclass it appropriately for various
kinds of accounts.
/**
Get the value of the account number. Account numbers are in the following
format: BBBBAAAAAA, where BBBB is the branch number and
AAAAAA is the branch account number.
*/
public long getAccountNumber()
{
return ( ( getBranchNumber() * 100000 ) + getBranchAccountNumber() );
}
/**
Set the account number. Account numbers are in the following
format: BBBBAAAAAA where BBBB is the branch number and
AAAAAA is the branch account number.
*/
public void setAccountNumber(int newNumber)
{
setBranchAccountNumber( newNumber % 1000000 );
setBranchNumber( newNumber / 1000000 );
}
Saturday, January 24, 2009
JavaScript ist in aller Munde – sowohl
JavaScript ist in aller Munde – sowohl im positiven als auch im negativen Sinne. Immer wieder geistern Horrormeldungen wie obige Empfehlung des BSI oder der Unfug aus der BamS durch die Presse. Grund dafür ist, dass den Browser-Herstellern – in diesem Falle vor allem Netscape (Netscape Navigator) und Microsoft (Microsoft Internet Explorer) immer wieder Fehler bei der Programmierung Ihrer Browser unterlaufen (bei Interesse: http://www.nat.bg/~joro/). Zwar werden eiligst Bugfixes zur Verfügung gestellt, aber der (Image-)Schaden ist schon eingetreten. Die andere Seite der Geschichte ist jedoch, dass keine Fälle bekannt sind, wonach Sicherheitslecks zu Schäden geführt haben. So hat die obige Pressemitteilung des BSI in der Fachpresse zu scharfer Kritik geführt, teilweise war von überzogener Panikmache die Rede. Die inhaltliche Qualität der Aussage aus der BamS entbehrt jeden Kommentars.
Ohne die Diskussion allzu sehr vertiefen zu wollen: Mit JavaScript kann man die eher beschränkten Möglichkeiten von HTML erweitern. Es handelt sich hierbei um eine clientseitige Programmiersprache, das heißt, alles läuft im Browser ab, und man muss keine besonderen Server-Voraussetzungen erfüllen. Letzterer Punkt ist (noch) ein großer Nachteil von serverseitigen Sprachen wie ASP, Perl, PHP und Konsorten, denn viele Hoster (und vor allem die günstigen Hoster) gestatten keine serverseitige Programmierung. Mit JavaScript ist dies jedoch alles kein Problem.
In den nun folgenden Kapiteln finden Sie eine komplette Einführung in die Sprache, stets anhand von praxisnahen Beispielen illustriert. Ich habe versucht, mich bei den Beispielen auf das Wesentliche – nämlich die JavaScript-Programmierung – zu konzentrieren, sodass die Beispiele grafisch bei weitem nicht ausgefeilt sind, aber sie erfüllen die gestellten Aufgaben.
Jedes Kapitel wird mit Fragen und Übungen abgeschlossen, sodass Sie das Erlernte gleich in die Tat umsetzen können. Das letzte Kapitel schließlich ist eine komplette Sprachreferenz, die Ihnen auch nach der Lektüre des Buches immer wieder als Nachschlagequelle dienen wird.
Ohne die Diskussion allzu sehr vertiefen zu wollen: Mit JavaScript kann man die eher beschränkten Möglichkeiten von HTML erweitern. Es handelt sich hierbei um eine clientseitige Programmiersprache, das heißt, alles läuft im Browser ab, und man muss keine besonderen Server-Voraussetzungen erfüllen. Letzterer Punkt ist (noch) ein großer Nachteil von serverseitigen Sprachen wie ASP, Perl, PHP und Konsorten, denn viele Hoster (und vor allem die günstigen Hoster) gestatten keine serverseitige Programmierung. Mit JavaScript ist dies jedoch alles kein Problem.
In den nun folgenden Kapiteln finden Sie eine komplette Einführung in die Sprache, stets anhand von praxisnahen Beispielen illustriert. Ich habe versucht, mich bei den Beispielen auf das Wesentliche – nämlich die JavaScript-Programmierung – zu konzentrieren, sodass die Beispiele grafisch bei weitem nicht ausgefeilt sind, aber sie erfüllen die gestellten Aufgaben.
Jedes Kapitel wird mit Fragen und Übungen abgeschlossen, sodass Sie das Erlernte gleich in die Tat umsetzen können. Das letzte Kapitel schließlich ist eine komplette Sprachreferenz, die Ihnen auch nach der Lektüre des Buches immer wieder als Nachschlagequelle dienen wird.
download java
Why download Java?
Java technology allows you to work and play in a secure computing environment.
Java allows you to play online games, chat with people around the world, calculate your mortgage interest, and view images in 3D, just to name a few.
After you've downloaded Java, visit java.com to check out Java in Action in your daily life. click java
Java technology allows you to work and play in a secure computing environment.
Java allows you to play online games, chat with people around the world, calculate your mortgage interest, and view images in 3D, just to name a few.
After you've downloaded Java, visit java.com to check out Java in Action in your daily life. click java
Friday, January 23, 2009
java
Latest Additions to The JavaScript Source
Tutorials: Coupling Async ScriptsThis article discusses two parallel issues: how async scripts make the page load faster, and how async scripts and inline scripts can be coupled using a variation of John Resig’s Degrading Script Tags pattern.
Forms: Enable Submit Button - This small script will disable the submit button and then re-enable it after a period of time. Useful for preventing duplicate submittals but also allows resubmission, if needed.
Tools: Venkman JavaScript Debugger - As Mozilla's JavaScript debugger, Venkman aims to provide a powerful JavaScript debugging environment for Gecko-based browsers. Firefox users can download the Venkman extension.
Ajax Tutorials: Overview of Popular JavaScript Frameworks - ASP.NET Ajax - This is the last installment of a JavaScript frameworks overview series. This tutorial highlights the main features of Microsoft's ASP.NET Ajax Framework, including controls, JavaScript Type extensions, asynchronous communications and debugging capabilities.
Forms: Verify E-mail Address - Collecting e-mail addresses in a form are important as they are generally the only method of contacting the user. This script will verify an e-mail address is entered correctly by requiring the user to re-enter the address, checking to make sure there is no typographical error. This script can also be used for passwords or other information that must be verified before being submitted.
More Additions: We add new scripts and tutorials on a regular basis. Be sure you didn't miss any of the most recent additions.
Tutorials: Coupling Async ScriptsThis article discusses two parallel issues: how async scripts make the page load faster, and how async scripts and inline scripts can be coupled using a variation of John Resig’s Degrading Script Tags pattern.
Forms: Enable Submit Button - This small script will disable the submit button and then re-enable it after a period of time. Useful for preventing duplicate submittals but also allows resubmission, if needed.
Tools: Venkman JavaScript Debugger - As Mozilla's JavaScript debugger, Venkman aims to provide a powerful JavaScript debugging environment for Gecko-based browsers. Firefox users can download the Venkman extension.
Ajax Tutorials: Overview of Popular JavaScript Frameworks - ASP.NET Ajax - This is the last installment of a JavaScript frameworks overview series. This tutorial highlights the main features of Microsoft's ASP.NET Ajax Framework, including controls, JavaScript Type extensions, asynchronous communications and debugging capabilities.
Forms: Verify E-mail Address - Collecting e-mail addresses in a form are important as they are generally the only method of contacting the user. This script will verify an e-mail address is entered correctly by requiring the user to re-enter the address, checking to make sure there is no typographical error. This script can also be used for passwords or other information that must be verified before being submitted.
More Additions: We add new scripts and tutorials on a regular basis. Be sure you didn't miss any of the most recent additions.
Subscribe to:
Posts (Atom)
