Abstract member types, Parameterized types and Pattern Matching.
Introduction Make your Iterable stack object visitable using Trait. This implementation varies from the implementation in previous post . This solution uses features like Abstract member type, Type Parameterization & Pattern Matching in Scala. This example illustrates how Abstract types and parameterized types can be used in tandem. PointVisitor encapsulates the details of Specialized Point Structures. Program package com.rajeshpatkar object Program { def main(args: Array[String]): Unit = { val p1 = Point2D(1,2) val p2 = Point3D(5,6,7) val p3 = PointPolar(1,34) val s1 = new PStack(); s1 < p1 < p2 < p3 ~ ; s1.visit(_*3).visit(_*5).visit(_-2); } } abstract class Point case class Point2D(val x:Int , val y:Int) extends Point case class Point3D(val x:Int,val y:Int,val z:Int) extends Point case class PointPolar(val r:Int ,val theta:Int) extends Point trait Visitable[T] extends It