I don't understand the need for an abstract type instead of just passing already existing concrete type:
type serialPortWrapper struct { conf *serialPortConfig port serial.Port deadline time.Time }
Abstraction has the advantage that you can pass different types with similar behavior to a function but this is not the case here (because there is only one type which implements the abstracted interface, namely serialPortWrapper)
On the other side, abstraction has disadvantage of reducing runtime performance because of type assertion and also reducing code readability (In all IDEs if you click on abstracted function call, it jumps to abstraction signature of the function rather than the real implementation).
2- In rtu_transport.go and inside the function ExecuteRequest() there is an unnecessary condition check.
err = rt.link.SetDeadline(time.Now().Add(rt.timeout)) if err != nil { return }
SetDeadline() function always return nil error. Basically it should not return any value.
Guten Tag,
1- In rtu_transport.go file there is a function that receives an argument of type rtuLink which is an abstract interface type:
func newRTUTransport(link rtuLink, addr string, speed uint, timeout time.Duration, customLogger *log.Logger) (rt *rtuTransport) {
I don't understand the need for an abstract type instead of just passing already existing concrete type:
type serialPortWrapper struct { conf *serialPortConfig port serial.Port deadline time.Time }
Abstraction has the advantage that you can pass different types with similar behavior to a function but this is not the case here (because there is only one type which implements the abstracted interface, namely serialPortWrapper)
On the other side, abstraction has disadvantage of reducing runtime performance because of type assertion and also reducing code readability (In all IDEs if you click on abstracted function call, it jumps to abstraction signature of the function rather than the real implementation).
2- In rtu_transport.go and inside the function ExecuteRequest() there is an unnecessary condition check.
err = rt.link.SetDeadline(time.Now().Add(rt.timeout)) if err != nil { return }
SetDeadline() function always return nil error. Basically it should not return any value.
MfG, /Vahid