★ wanayoo — archive 1999 http://javaboutique.webdeveloper.com/tutorials/JavaOO/LSP.htmlNouvelle recherche | Portail wanayoo
Computer Digital Expo

Find the lowest price for a variety of products:


Featured Categories:
Computers
Digital Cameras
Home Theatre
Video Games
Laptops
Software
Electronics
PDA's


Find a Web Host With:
CGI Access
DB Support
NT Servers
UNIX Servers
Telnet Access

advanced search
Internet News
Internet Investing
IT
Windows Technology
Linux/Open Source
Developer
Interactive Marketing
xSP Resources
Small Business
Wireless Internet
Downloads
Internet Resources
Internet Lists
International
EarthWeb
Career Resources

Search internet.com
Advertise
Corporate Info
Newsletters
E-mail Offers
Be a Commerce Partner
Business Search
Track Defects Online
Best Deals on PDAs!
Register Domains
Web Hosting
Software Licenses
Shop Digital Cameras
Online Credit Reports
Find a Web Host
Website Monitoring
FlashKit
Gif.com
HierMenusCentral
JavaBoutique
JavaScript.com
JavaScriptSource
WebDev Jobs
JustSMIL
ScriptSearch
StreamingMediaWorld
Web Hosts
WebDevelopersJournal WDVL
WebDeveloper.com
WebReference.com
XMLFiles.com
CGI
HTML
Java
JavaScript
Web Design and Promotion
Web Site Development
E-mail Address:


Can you receive
HTML e-mail?

Yes   No

Zip Code:


Tutorials : Liskov's Substitution Principle :

LSP compliant solution

One of the main lessons I learned is that sub-typing needs to be done with respect to the behaviour of the types and not with respect to the data only. In this aspect, the SpecialCurrentAccount IS NOT A CurrentAccount. A banker will shout at me for sure if I say this to him. But for you the intelligent programmers this would make sense. This is because they do not exhibit the same behaviour against the same message. I decided to break the hierarchy and come up with is new design with Account as an abstract base type and CurrentAccount and SpecialCurrentAccount as its sub-types.

The abstract Account class declares an abstract method closeAccount(), which is implemented by both CurrentAccount and SpecialCurrentAccount. I have now changed the interface class to accept an Account type of Object as opposed a particular type of Account Object. The new interface class looked like this.

public boolean closeAnAccount(Account ac)

With this hierarchy, what may surprise you is that we have not changed the implementation of the closeAccount() method in any of the classes. The pre-conditions and the post-conditions remain the same. But in essence, what has happened is that the user will not make any assumption about the behaviour of the account object he is dealing with. This makes the module more maintainable and reusable in the sense that now it is very easy to add another type of account which may impose some other pre-condition and post-condition without breaking the LSP and Design by Contract.

No overriding!!!

It may seem from the above discussion that overriding is the main problem with LSP and in that case inheritance makes no sense. To some extent, it is puzzling but always keep the Design by Contract principle in mind before you override. If you are unable to comply with the same, then it might be worth revisiting your class diagrams. Always make sure that the derived class must enforce less strict pre-conditions while overriding any base class method. Try to think about the situation on your own and surely you will come up with some logic why LSP is so important for a good OO design.

Next month

Next month, look forward to some of the other important principles of the OO design. Hope this series will help you design a better Object Oriented Software.


Applet Index
(sorted alphabetically)

A B C D E F G H I J K
L M N O P Q R S T U
V W X Y Z #s
The Java Source
(applets w/source code)

A B C D E F G H I J K
L M N O P Q R S T U
V W X Y Z

How to Add Java Applets to Your Site

New on the Java Boutique:

New Article:
A Barebones Guide to Usability Testing
At first glance, usability testing may seem like unnecessary, or additional work. In todays budget slashed world, it is not uncommon for projects not to have the luxury of this valuable phase. This is a dangerous path to tread. Let's look at how we can incorporate usability testing into our design process.
... [more articles]

New Tutorial:
Java Certification Path API
Certificate based security forms the basis for SSL (Secure socket layer) transactions? Every year billions of transactions involving trillions of dollars are done safely using the SSL protocol. This week we'll look at the role of the Java certification path API and see how it provides a mechanism to implement certification path functionality.
... [more Tutorials]

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

internet.com logo






Developer News

Apache Updates Popular HTTP Server

Is Adobe Targeting Microsoft's InfoPath?

Oracle Takes on Collaboration Market



Database Journal Launched!
Jupiter Media has announced the launch of Database Journal. DBJ offers SQL courses and other database related resources for beginner to expert developers.



Scrolling Text
This is a suite of three applets that displays scrolling text using an array of images. The detailed description of array of each applet is provided.
Download of the Week
DS PageFlipText
This applet displays a page-flip effect between texts. Over the animation you can also insert an image and a scroll-text.

JB User Poll
Which version of Java do you use the most?
The JavaBoutique Top 15:
1. ChompText
2. PulseText
3. DJPopMenu
4. NavBar
5. RushHour
6. PingPong
7. 3DMaze
8. AScroll2
9. Viewer
10. AnimLetters_anim
11. Encyclo
12. Distorter
13. BMI
14. MusicKeyboard
15. AdvPano
Want more? Check out our Top 100!

Refer-It
Affiliate Program and Referral Directory.
New on internet.com
Cisco Exploit Is Active
Security researchers have increased the threat level on a vulnerability affecting Cisco routers and switches after an exploit was posted to a popular mailing list.

The 3G Tokyo Time Machine
What will a 3G wireless future be like? Step into DoCoMo's time machine and find out.

SBA's Whistling Dixie
Small businesses throughout the South are extended the opportunity to meet one-on-one with government agencies and large corporations to obtain near-term contract opportunities for their products and services.


Jupitermedia is publisher of the internet.com and EarthWeb.com networks.
Copyright 2003 Jupitermedia Corporation All Rights Reserved.

Legal Notices,  Licensing, Reprints, & Permissions,  Privacy Policy.
http://www.earthweb.com/
http://www.internet.com/