“A Taste of Concurrency”
来源:互联网 发布:云计算是什么意思 编辑:程序博客网 时间:2024/05/16 12:16
shapes.scala:
// code-examples/IntroducingScala/shapes.scala
package shapes {
class Point(val x: Double, val y: Double) {
override def toString() = "Point(" + x + "," + y + ")"
//重载toString方法
}
abstract class Shape() {
def draw(): Unit
}
//val----->强类型
class Circle(val center: Point, val radius: Double) extends Shape {
def draw() = println("Circle.draw: " + this)
override def toString() = "Circle(" + center + "," + radius + ")"
}
class Rectangle(val lowerLeft: Point, val height: Double, val width: Double)
extends Shape {
def draw() = println("Rectangle.draw: " + this)
override def toString() =
"Rectangle(" + lowerLeft + "," + height + "," + width + ")"
}
class Triangle(val point1: Point, val point2: Point, val point3: Point)
extends Shape {
def draw() = println("Triangle.draw: " + this)
override def toString() =
"Triangle(" + point1 + "," + point2 + "," + point3 + ")"
}
}package com.ch1
// code-examples/IntroducingScala/shapes.scala
package shapes {
class Point(val x: Double, val y: Double) {
override def toString() = "Point(" + x + "," + y + ")"
//重载toString方法
}
abstract class Shape() {
def draw(): Unit
}
//val----->强类型
class Circle(val center: Point, val radius: Double) extends Shape {
def draw() = println("Circle.draw: " + this)
override def toString() = "Circle(" + center + "," + radius + ")"
}
class Rectangle(val lowerLeft: Point, val height: Double, val width: Double)
extends Shape {
def draw() = println("Rectangle.draw: " + this)
override def toString() =
"Rectangle(" + lowerLeft + "," + height + "," + width + ")"
}
class Triangle(val point1: Point, val point2: Point, val point3: Point)
extends Shape {
def draw() = println("Triangle.draw: " + this)
override def toString() =
"Triangle(" + point1 + "," + point2 + "," + point3 + ")"
}
}
shapesActor.scala:
package com.ch1
package shapes {
import scala.actors.Actor._
import scala.actors._
import com.ch1.shapes._
object ShapeDrawingActor extends Actor {
def act() {
loop {
receive {
case s: Shape => s.draw()
case "exit" => println("exiting..."); exit
case x: Any => println("Error: Unknown message! " + x)
}
}
}
}
}
package shapes {
import scala.actors.Actor._
import scala.actors._
import com.ch1.shapes._
object ShapeDrawingActor extends Actor {
def act() {
loop {
receive {
case s: Shape => s.draw()
case "exit" => println("exiting..."); exit
case x: Any => println("Error: Unknown message! " + x)
}
}
}
}
}
shapesScript.scala:
package com.ch1
object shapesScript {
def main(args: Array[String]): Unit = {
import shapes._
ShapeDrawingActor.start()
ShapeDrawingActor ! new Circle(new Point(0.0, 0.0), 1.0)
ShapeDrawingActor ! new Rectangle(new Point(0.0, 0.0), 2, 5)
ShapeDrawingActor ! new Triangle(new Point(0.0, 0.0),
new Point(1.0, 0.0),
new Point(0.0, 1.0))
ShapeDrawingActor ! 3.14159
ShapeDrawingActor ! "exit"
}
}
object shapesScript {
def main(args: Array[String]): Unit = {
import shapes._
ShapeDrawingActor.start()
ShapeDrawingActor ! new Circle(new Point(0.0, 0.0), 1.0)
ShapeDrawingActor ! new Rectangle(new Point(0.0, 0.0), 2, 5)
ShapeDrawingActor ! new Triangle(new Point(0.0, 0.0),
new Point(1.0, 0.0),
new Point(0.0, 1.0))
ShapeDrawingActor ! 3.14159
ShapeDrawingActor ! "exit"
}
}
- “A Taste of Concurrency”
- A taste of Chengdu
- A Taste of scala
- A Taste of `Future`
- [心得] The Taste Of Python
- Paul Graham - Taste of Makers
- A Taste of AOP from Solving Problems with OOP and Design Patterns (Part I)
- A Taste of AOP from Solving Problems with OOP and Design Patterns (Part II)
- A Taste of AOP from Solving Problems with OOP and Design Patterns (Part III)
- A Taste of AOP from Solving Problems with OOP and Design Patterns (Part I)
- A Taste of AOP from Solving Problems with OOP and Design Patterns (Part II)
- A Taste of AOP from Solving Problems with OOP and Design Patterns (Part III)
- A Taste of AOP from Solving Problems with OOP and Design Patterns (Part I) zz
- A Taste of AOP from Solving Problems with OOP and Design Patterns (Part II) zz
- A Taste of AOP from Solving Problems with OOP and Design Patterns (Part III) zz
- A Taste of American: Thanksgiving Dinner -- 美国味道之旅:感恩节大餐(一)
- A Taste of American: Thanksgiving Dinner -- 美国味道之旅:感恩节大餐(二)
- Color, so that a woman turning into a butterfly out of the dressing to enhance your taste
- 展示一下爱机,诺基亚
- 决定入驻CSDN,将原先博客空间进行转接
- joj2431
- HDU 1856 more is better
- linux GDB调试程序
- “A Taste of Concurrency”
- 进程间通信机制之三:共享内存
- Windows字符串类型 CHAR* WCHAR* LPSTR LPCSTR
- 内部类的方法(外部调用内部类的方法)
- JAVA设计模式
- 程序员面试100题之八:不要被阶乘吓倒(二进制表示中最低位1的位置 )
- 中国软件公司排行和世界著名的软件公司
- mvn打包spring工程成jar时报Unable to locate Spring NamespaceHandler for XML schema namespace错误解决办法
- JSP播放视频