设计模式 flyweight_test 实现

  • 2022-07-21
  • 浏览 (1067)

golang 设计模式 flyweight_test 代码实现

package flyweight

import "testing"

func ExampleFlyweight() {
	viewer := NewImageViewer("image1.png")
	viewer.Display()
	// Output:
	// Display: image data image1.png
}

func TestFlyweight(t *testing.T) {
	viewer1 := NewImageViewer("image1.png")
	viewer2 := NewImageViewer("image1.png")

	if viewer1.ImageFlyweight != viewer2.ImageFlyweight {
		t.Fail()
	}
}

目录

go 设计模式

相关文章

享元模式

设计模式 flyweight 实现

0  赞