Posts

Showing posts from May, 2021

Marker Interfaces

 So today I was doing some coding on a personal project and I had this scenario where I have a class that contains an object representing some data , but the nature of this data is very diverse so I could not create an interface to represent it. But I do needed to "mark it" as something belonging to an expected type. So what did I do ? Well nothing :P , I was using typescript and I left that member type as "any" but that looked so ugly to me so I had to do something! So after thinking for a while I thought "Ok , I will have an empty interface ! To mark my classes. But are empty interfaces even allowed??" . So I googled my concern and found out that it is indeed a thing and it is called a Marker Interface. https://en.wikipedia.org/wiki/Marker_interface_pattern So basically marker interface means an empty interface that you use to mark something. But it does have a lot of bad side effects according to SO and many other online platforms and in modern language