![]() ![]() The students were told, by the way, that this wasn't an entirely live demo and that the instructor had prepared before. #CALCULATE PI FROM POLYMORPHISM TABLE CODE#As a result, the code we actually built differs a bit from this. ![]() All the while the pair of programmers is discussing issues about the code such as names and structure as well as algorithms. This path involved writing a simple test and running it (it fails of course), writing a bit of code to make the test pass, running the test again, etc. Presenting the code does not, unfortunately, give you any idea about the path used in its creation. The GUI is also too simple, using only a flow layout to avoid complication. Some of the classes here should be inner to the model, for example. Note that the code design is intentionally not perfect as the students were expected to do some refactoring and add additional features after the demonstration - again in a pair programming mode. Given more time for refactoring we would have done Typesafe Enumeration as well. The other patterns in the code are Singleton, Null Object, and Immutable. I also took time out during the demonstration to discuss and motivate the Strategy and Decorator patterns. Since the students were novices and the instructor took the "driver" role in the pair, the student "navigator" could not contribute much, though several times the student caught errors made by the "driver." The instructor also took suggestions from the "navigator" on method names, etc. A different student paired with the instructor for each session. The demonstration took about 6 hours total over three sessions. ![]() Nowhere was there any discussion of Java syntax, though questions were taken and answered while the demonstration was going on. The first Java shown was an interface that defined the behavior of the "Actors" in a role play. Prior to this demonstration, the students were given a two-hour lecture/discussion in which the key ideas (encapsulation, message passing, and polymorphism) were discussed and motivated through various metaphors and role play exercises. In addition, it writes class and method skeletons with needed constructors, methods to be implemented from interfaces, and JavaDoc skeletons. This was facilitated by using Eclipse ( ) which is both integrated with JUnit and has a refactoring layer. With another hour we could probably have finished what is presented here.Īs the code was being built in front of the class, no code was written for the calculator unless we first had a test for it. In six hours (three two-hour sessions) we developed most of this except the GUI and the inner NullOperator class. This code was not shown to students, but rather was re-built live in front of the class using an overhead projector while pair-programming ( ) with one of the members of the class. What is shown here was developed by myself in preparation for a two day short course. It was developed using the "test first" methodology advocated in eXtreme Programming (XP - ). The third part is a set of tests using the JUnit ( ) testing framework. The GUI is completely separate, similar to the model-view-controller architecture. As such it has only a functional interface. The model implements the calculator itself. It has been used as the first introduction to Java and object-orientation with a group of adults. It implements the key parts of a simple four function algebraic calculator that has no knowledge of operator precedence. This page presents the Java code of a calculator I developed to demonstrate what can be done in an object-oriented language without using if or while. Polymorphic Calculator A Simple Calculator for Novice Learning Joseph Bergin ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |