openclose

package
v0.0.0-...-a5c2be1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2021 License: MIT Imports: 1 Imported by: 0

README

开闭原则

软件实体应该对扩展开放,对修改关闭。一个软件实体应该通过扩展来实现变化,而不是通过修改已有的代码来实现变化。

多扩展开放,修改关闭

  • 逻辑变化
  • 子模块变化
  • 可见视图变化

为什么用开闭原则

  • 开闭原则对测试的影响

保证不产生有毒代码(Poisonous Code)

  • 开闭原则可以提高复用性

  • 开闭原则可以提高可维护性

  • 面向对象开发的要求

如何使用开闭原则

1.抽象约束

  • 不出现接口不存在的public func
  • 尽量使用接口,go中虽然没有继承,但是可以用组合
  • 抽象层尽量稳定

2.元数据控制模块行为 3.制定项目章程 4.封装变化

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintBook

func PrintBook()

func PrintMixBook

func PrintMixBook()

func PrintOffBook

func PrintOffBook()

Types

type Book

type Book struct {
}

type BookStore

type BookStore struct {
	// contains filtered or unexported fields
}

type ComputerBook

type ComputerBook struct {
	// contains filtered or unexported fields
}

func NewComputerBook

func NewComputerBook(name, author, scope string, price int) *ComputerBook

type IBook

type IBook interface {
	// contains filtered or unexported methods
}

type IComputerBook

type IComputerBook interface {
	IBook
	// contains filtered or unexported methods
}

type NovelBook

type NovelBook struct {
	// contains filtered or unexported fields
}

func NewNovelBook

func NewNovelBook(name, author string, price int) *NovelBook

type OffNovelBook

type OffNovelBook struct {
	// contains filtered or unexported fields
}

func NewOffNovelBook

func NewOffNovelBook(name, author string, price int) *OffNovelBook

Jump to

Keyboard shortcuts

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