DEV Community

Discussion on: Understanding SOLID Principles: Liskov Substitution Principle

Collapse
 
almosaiki0 profile image
almokhtar

I will implement the ReadonlyDocument.save() like this :

if instanceof(doc) is ReadonlyDocment :
throw an Error
else :
super().save()

Collapse
 
kodenix profile image
Alberto Morales

Instanceof is a antipattern, if you need add new subtypes, requiere add other validation and you client is hight coupled with subtypes, if you change the subtypes class need change on client ( break Open Close)