Object-Oriented Analysis, Design and Implementation by Brahma Dathan & Sarnath Ramnath
Author:Brahma Dathan & Sarnath Ramnath
Language: eng
Format: epub, pdf
Publisher: Springer International Publishing, Cham
The getUpperTriangle method does not pose any problem for our Pixel class, since it will always return null. Our troubles start with existing client classes, whose methods have been using the methods of SolidRectangle. Consider the following method in a client class that takes as its input parameter a SolidRectangle object.
This code was written by a client using SolidRectangle, but unaware of Pixel. Since the two corners are set to two distinct points, triangle1 will not be null, and things will be fine. Now if this method is invoked and a reference to a Pixel object is passed as the actual parameter, both the corners will end up being assigned the same point, triangle1 will be null, and we end up with a NullPointerException. Note that there is no simple fix; we may just have to find such code in all the methods of the client classes, and either check for null pointers or check the type of the objects stored in the SolidRectangle references at runtime.
At every step of the this process our choices seemed logical, but we ended up with an undesirable state of affairs. So it is natural to ask: what went wrong? The answer lies in a precise definition the is-a relationship: A pixel object ‘is-a’ SolidRectangle object if and only if the behaviour of Pixel objects conforms to the behaviour of SolidRectangle objects in all situations. The above example shows that the behaviour of getUpperTriangle does not exhibit such conformance when invoked in conjunction with the setCorner methods. One could argue, perhaps, that the method getUpperTriangle is itself poorly designed, but that is really not a choice that we can make now. It is important to keep in mind that we are inheriting from the existing class SolidRectangle and we must accept all its methods. To cast this in terms of the formal statement of the LSP, when we substitute Pixel for SolidRectangle the behaviour of any program should remain unchanged. What we have shown here is that for the program clientMethod, the behaviour changes when such a substitution is made.
The caveat here for the programmer extending a class is therefore that one must check all behaviours of the class being extended, even in situations where a subset relationship exists between the corresponding ‘real-world’ entities.
Download
Object-Oriented Analysis, Design and Implementation by Brahma Dathan & Sarnath Ramnath.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Coding Theory | Localization |
Logic | Object-Oriented Design |
Performance Optimization | Quality Control |
Reengineering | Robohelp |
Software Development | Software Reuse |
Structured Design | Testing |
Tools | UML |
Deep Learning with Python by François Chollet(11922)
Hello! Python by Anthony Briggs(9388)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9353)
The Mikado Method by Ola Ellnestam Daniel Brolund(9321)
Dependency Injection in .NET by Mark Seemann(8867)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7860)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7352)
Grails in Action by Glen Smith Peter Ledbrook(7305)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7127)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(5969)
Kotlin in Action by Dmitry Jemerov(4654)
Practical Vim (for Kathryn Amaral) by Drew Neil(3734)
Cracking the GRE Premium Edition with 6 Practice Tests, 2015 (Graduate School Test Preparation) by Princeton Review(3602)
Linux Device Driver Development Cookbook by Rodolfo Giometti(3452)
Learn Windows PowerShell in a Month of Lunches by Don Jones(3253)
Learning Java by Patrick Niemeyer & Daniel Leuck(2875)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(2847)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(2847)
Microservices with Go by Alexander Shuiskov(2641)