How to Create Interface ??

In ruby basically we have no built in option for creating Interface. We just need to force the base class method to act like an Interface method.

Example :–>

class InterfaceName

def show

raise ‘Exception! This method must be implemented before accessing it.’

end

end

—————————

class SubclassName < InterfaceName

….

end

————————

If we want to do the following then it raises Exception…

SubclassName . show

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: