add: interface 简单的用法
This commit is contained in:
12
interface/example1/sensor/sensor.go
Normal file
12
interface/example1/sensor/sensor.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package sensor
|
||||
|
||||
type Sensor interface {
|
||||
Add()
|
||||
Delete()
|
||||
Update()
|
||||
Search()
|
||||
}
|
||||
|
||||
func AddSensor(s Sensor) {
|
||||
s.Add()
|
||||
}
|
||||
30
interface/example1/sensor/sensorimpl/ftp.go
Normal file
30
interface/example1/sensor/sensorimpl/ftp.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package sensorimpl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"golanglearn/interface/example1/sensor"
|
||||
)
|
||||
|
||||
type Ftp struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func (f *Ftp) Add() {
|
||||
fmt.Println("ftp sensor", f.Name)
|
||||
}
|
||||
|
||||
func (f *Ftp) Delete() {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (f *Ftp) Update() {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (f *Ftp) Search() {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func NewFtp(name string) sensor.Sensor {
|
||||
return &Ftp{Name: name}
|
||||
}
|
||||
30
interface/example1/sensor/sensorimpl/rtsp.go
Normal file
30
interface/example1/sensor/sensorimpl/rtsp.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package sensorimpl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"golanglearn/interface/example1/sensor"
|
||||
)
|
||||
|
||||
type Rtsp struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func (r *Rtsp) Add() {
|
||||
fmt.Println("add sensor", r.Name)
|
||||
}
|
||||
|
||||
func (r *Rtsp) Delete() {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (r *Rtsp) Update() {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (r *Rtsp) Search() {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func NewRtsp(name string) sensor.Sensor {
|
||||
return &Rtsp{Name: name}
|
||||
}
|
||||
Reference in New Issue
Block a user