Skip to main content

Posts

Showing posts from August, 2022

How to create your own enum type with the regular classes?

You will always have the joy of using enums, but have you ever thought that enums demonstrate the common characteristics of Object Oriented Design? I.e inheritance and abstraction. So what stops you from creating your own enum construct with the available constructs, i.e classes. I was just playing around with them and could build one. Let's first get to know the characteristics of an enum. Characterics of an enum Enums cannot be instantiated with the 'new' keyword since the constructor is private. Enums can contain only a finite set of states. i.e the value/s an Enum can contain should have been defined already. Enums do behave as regular classes complying with the OOD features like inheritance, polymorphism, encapuslation and abstraction The only exception I have noticed is that it does not allow generics, at least in Java 8. Those above properties can be achieved with some already available constructs. Good news is additional benefits can also be gained; generics!. Since...