How interface ( Object Oriented Programming concept) works in Python ? Also Please provide me some suitable example [closed]

StackOverflow https://stackoverflow.com/questions/19370977

Question

How interface ( Object Oriented Programming concept) works in Python ? Also Please provide me some suitable example.

Was it helpful?

Solution

Generally Interfaces are used for linking two section(module) in application(s). I would call it a bunch(one or many) of method pointers. You may face with interfaces to much when you are trying to contract with another module or application, because a standard way should be present here in order to making communication between two module.


Let say I have programmed a module about listening on a certain files in OS, and you would to use my module. so how do we need understand each other?! there is a possible solution, you would pass a method pointer(interface) to my module, then my module will trigger(invoke) the pointer as event occurred. so the first thing we need here is defining the interface(method pointer) Listener Interface

//code: java
public interface Listener{
 void onEvent(String fileName);
}

in above interface, there is one method defined. the onEvent method is called when a file gets changed. this method has an argument String fileName which points to the file name has changed.


So here, my module uses(invokes) the interface, and your modules implements it. so this is the point, we could interact with each other by interfaces.

So for such this scenarios the UML diagram would be like this. My modules requires the interface. Your module implements the interface. Ring-Bell model

As interface code example above, as you see, the interface is nothing itself, it acts liek a pointer, but it ensure the target class(MyModule) that the target class has a method called onEevent.

I hope I could give some hand.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top