单一职责原则(SRP)
Golang Demo
package singleresponsibility
type CourseContent interface {
getCourseName() string
getCourseVideo() []byte
}package singleresponsibility
type CourseManager interface {
studyCourse()
refundCourse()
}package singleresponsibility
import "fmt"
type Course struct {
}
func (Course) studyCourse() {
fmt.Println("study")
}
func (Course) refundCourse() {
fmt.Println("refund")
}
func (Course) getCourseName() string {
return "course name"
}
func (Course) getCourseVideo() []byte {
return nil
}Java Demo
接口单一职责原则的体现
类单一职责原则的体现。
UML (接口为例)

补充另一个版本的Java/Scala Demo 以及源码解析
Java Demo_
Scala Demo
UML_
源码解析
Last updated