question about the good_practices.md #1508
Replies: 1 comment
-
The idea here to promote loose coupling and maintain flexibility. for example, let's go with the infamous shapes example: Let's say we have a simple application that manages a collection of shapes, such as circles and rectangles. We want to define an interface called interface Shape {
getArea();
getPerimeter();
} Now, let's consider a specific implementation of a circle: class Circle {
constructor(radius) {
this.radius = radius;
}
getArea() {
return Math.PI * this.radius * this.radius;
}
getPerimeter() {
return 2 * Math.PI * this.radius;
}
// Circle-specific methods...
} For this Circle class, we don't need to create another interface Another example would be if you have a userRepo (wrapper for an database interfacing functions). You'd have an interface classDiagram
class IUserRepo {
<<interface>>
+create(user: User): User
+update(user: User): User
+delete(userId: string): boolean
}
if you're going to have different versions of this: one that interfaces with SQL and another with Mongo, you would not need to create different interfaces, rather, just use this one here. Hope that helps |
Beta Was this translation helpful? Give feedback.
-
someone can give us an example of this good practice ?
Avoid implementation-specific interface types
documentation.Avoid implementation-specific interface types
I know sometimes we don't need an Interface for a specific class/service/behaviour, and doing this it's clearly useless for the maintainer/developper but why this is an anti pattern exactly ? Or may I'm wrong of my understanding
Beta Was this translation helpful? Give feedback.
All reactions