Viewing old version 09b316abe43a834affd8cea43f0471257cbd1d75; View Current
Classes are defined much as they are in Java. Here is a simple class that models a circle.
This is quite different from Java; it’s much more compact, but it also gives you a tiny flavor of the functional side of Scala. Notice how all the method definitions use the equals sign? You are creating a sort-of expression for each one, but it’s evaluated when you call the method.
You can also extend classes much as with Java. Note that when we indicate the class we’re extending, we can pass up constructor values. Also note that superclass methods are called with the
super keyword, just as in Java. And yes, I realize this is a horrible example of Object-Oriented design.
This isn’t a comprehensive overview of everything you can do, but gives you some of the flavor of classes in Scala.
My Thoughts on this Feature
Pretty simple. The constructor stuff is great, and the variable/property thing is really nice, too.
Last Updated 11/19/2009 at 12:36:23 AM by davecblog comments powered by Disqus
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.