bridge

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2020 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Circle

type Circle struct {
	DrawAPI DrawAPI
	// contains filtered or unexported fields
}

func (*Circle) Draw

func (c *Circle) Draw()

type DrawAPI

type DrawAPI interface {
	DrawCircle(int, int, int)
}

强关联改换成弱关联,将两个角色之间的继承关系改为关联关系。由继承(或颜色在每个类中分别定义)改为组合。 以形状、颜色等属性分为多个维度,每个维度一个类型,这些类型通过组合的方式关联在一起。复用的方式减少代码量。

type GreenCircle

type GreenCircle struct {
	Color string
}

green circle

func (*GreenCircle) DrawCircle

func (gc *GreenCircle) DrawCircle(radius, x, y int)

type IShape

type IShape interface {
	Draw()
}

shape

func NewCircle

func NewCircle(radius, x, y int, drawAPI DrawAPI) IShape

type RedCircle

type RedCircle struct {
}

red circle

func (*RedCircle) DrawCircle

func (rc *RedCircle) DrawCircle(radius, x, y int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL