preview

Visual And Functional Programing Principles

Decent Essays

Scala is a modern, multi-paradigm language designed to express common programming patterns in a concise, elegant, and type-safe manner. It carefully integrates object-oriented and functional programing principles. A more detailed explanation of Scala’s object-oriented features can be found in the “Object-Oriented Features” below. A brief discussion of Scala’s hybrid functional features can be found in the subsection “Hybrid Features of Scala” below. Object-Oriented Features Encapsulation Scala does support encapsulation. Since it is based off of Java, which is an object oriented language, it supports all the OOP features from Java. Functions in Scala are objects as well. This causes every operation to be a method call. Inheritance Inheritance is supported in Scala. The base class of scala is any. All classes inherit directly or indirectly from the any class, containing all of the methods available in the proceeding classes. A class in Scala cannot directly be a child of two separate classes; however, a class can extend more than one class using traits and mixin class composition similar to interfaces in Java. Example XX - Defining a Trait in Scala and an Inheriting Class (Trait) Trait Similarity { def isSimilar ( x:Any ) : Boolean def isNotSimilar ( x:Any ) : Boolean = !isNotSimilar ( x ) } Class Point( xc: Int, yc: Int ) extends Similarity { var x: Int = xc var y: Int = yc def isSimilar ( obj: Any ) : = obj.isInstanceOf[ Point ] && obj.asInstanceOf[ Point ].x

Get Access