Acta Informatica Pragensia 2016, 5(1), 34-45 | DOI: 10.18267/j.aip.834014

A Solution to the Square-Rectangle Problem Within the Framework of Object Morphology

Zbynìk ©lajchrt
Department of Information Technologies, Faculty of Informatics and Statistics, University of Economics, Prague, W. Churchill Sq. 4, 130 67 Prague 3, Czech Republic

The square-rectangle problem is often cited as an illustration of pitfalls arising when using object-oriented programming (OOP). A number of solutions have been proposed, however, according to the author, none of them solve the problem satisfactorily, mainly because they tackle the problem from within the current OOP paradigm. This paper presents another solution stemming from object morphology (OM), a new object-oriented paradigm developed to model mutable phenomena. In the framework of OM the problem can be solved directly under the basic OM principle that an object may mutate not only with regard to its state, but also with regard to its type. The main contrast between the presented and the other solutions is that constraint violations caused by changes in an object's state are no longer necessarily considered errors; instead, they may be interpreted as triggers initiating a mutation of the object's type. The solution is demonstrated using Morpheus, a proof-of-concept implementation of OM in Scala.

Keywords: Square-rectangle problem, Circle-ellipse problem, Liskov substitution principle, Object-oriented programming, Object morphology, Scala, Mutable objects

Received: March 24, 2016; Revised: June 2, 2016; Accepted: June 13, 2016; Published: June 29, 2016  Show citation

ACS AIP APA ASA Harvard Chicago Chicago Notes IEEE ISO690 MLA NLM Turabian Vancouver
©lajchrt, Z. (2016). A Solution to the Square-Rectangle Problem Within the Framework of Object Morphology. Acta Informatica Pragensia5(1), 34-45. doi: 10.18267/j.aip.83
Download citation

References

  1. Boult, T. E., Fenster, S. D., & Kim, J. W. (1994). Dynamic Attributes, Code Generation and the IUE. In Proceedings of the ARPA Image Understanding Workshop (pp. 405-422). Monterey.
  2. Cline, M., & Lomow, G. (1995). C++ FAQs: Frequently Asked Questions. Reading: AddisonWesley.
  3. Groovy Documentation. (2016). Traits. Retrived from: http://docs.groovy-lang.org/latest/html/documentation/core-traits.html.
  4. Grosberg, J. (1997). Design guidelines for Is-A hierarchies. Dr. Dobb's Journal. Retrived from: http://www.drdobbs.com/database/design-guidelines-for-is-a-hierarchies/184410208
  5. Liskov, B. (1988). Data abstraction and hierarchy. SIGPLAN Notices, 23(5), 17-34. doi: 10.1145/62138.62141 Go to original source...
  6. Majorinc, K. (1998). Ellipse-Circle Dilemma and Inverse Inheritance. In Proceedings of the 20th International Conference of Information Technology Interfaces. Pula. Retrieved from: http://kazimirmajorinc.com/Documents/1998,-Majorinc,-Ellipse-circle-dilemma-and-inverse-inheritance.pdf.
  7. Martin, D. (2009). Gettersand Setters in Scala. Retrieved from: http://dustinmartin.net/getters-and-setters-in-scala/.
  8. Martin, R. C. (2002). Agile Software Development, Principles, Patterns, and Practices. London: Pearson.
  9. Meyers, S. (1994). More Effective C++. Reading: Addison-Wesley.
  10. Madsen, O. L. (2006). Open Issues in Object-Oriented Programming - A Scandinavian Perspective. Software: Practice and Experience, 25(S4), 3-43. doi: 10.1002/spe.4380251303 Go to original source...
  11. Rumbaugh, J., Blaha, M., Premerlani, W., Eddy, F., & Lorensen, W. (1991). Object-Oriented Modeling and Design. New Jersey: Prentice-Hall.
  12. Scala Documentation. (2016). A Tour of Scala: Traits. Retrieved from: http://www.scala-lang.org/old/node/126.
  13. ©lajchrt, Z. (2015a). Object Morphology. A draft of the dissertation thesis. Retrieved from: https://github.com/zslajchrt/morpheus/raw/master/src/main/doc/thesis/thesis.pdf.
  14. ©lajchrt, Z. (2015b). Morpheus, a Proof-of-Concept Implementation of Object Morphology in Scala. Retrieved from: https://github.com/zslajchrt/morpheus.
  15. ©lajchrt, Z. (2016). The Square-Rectangle Solution in Morpheus. Retrieved from: https://github.com/zslajchrt/morpheus-tutor/blob/master/src/main/scala/org/cloudio/morpheus/square/Square.scala.

This is an open access article distributed under the terms of the Creative Commons Attribution 4.0 International License (CC BY 4.0), which permits use, distribution, and reproduction in any medium, provided the original publication is properly cited. No use, distribution or reproduction is permitted which does not comply with these terms.