‫Welcome back.
‫Let's continue with abstraction in Kotlin.
‫And in this video we'll learn about interfaces.
‫An interface is a blueprint for a set of functions or properties that a class must implement.
‫An interface defines a contract specifying which methods and properties a class implementing the interface
‫must provide.
‫Classes can implement one or more interfaces, allowing them to exhibit the behavior specified by those
‫interfaces.
‫For this example, I'll create a new interface and I'll name it as Robot Actions.
‫Click enter and Android Studio will open it.
‫This is marked as interface data.
‫Abstraction is the process of hiding certain details and showing only essential information to the user.
‫Abstraction can be achieved with either abstract classes or interfaces.
‫In the previous video, we learned about the abstraction and the abstract class and functions, and
‫in this video we'll continue with the abstraction and we'll learn about interfaces.
‫Here I'll define an interface for robots that can start and stop.
‫So I'll create a function start and a function stop.
‫And by the way, you can't create abstract functions because all the functions inside the interface
‫are abstract and should be implemented and overrided in the classes that implement the robot actions
‫interface.
‫And in this example, I'll move this abstract function from the class general robot.
‫For that I need to remove the start function.
‫In order to implement this interface in any class.
‫It's very simple.
‫It's like extending.
‫So we specify this column and we specify the interface name.
‫Robots action.
‫By the way there is no need to implement the methods here in the abstract class.
‫But if we go to here we can see that there are three errors we need to implement the start and the stop
‫function that are inherited from the robot actions interface.
‫So let me go to the Super robot class.
‫Click on this right bulb or Alt Plus enter to implement the members.
‫We have two members that we should implement.
‫Click okay and we override it.
‫The start and stop methods of this interface.
‫Also, for the ordinary robot it's the same and for the firing robot implement the methods and we need
‫to implement again the start and the stop.
‫So every class that inherits from the general robot will inherit from robots actions interface and should
‫implement the start and the stop functions.
‫Here you can write whatever you want for your classes.
‫For this start, I'll create a print starting fire robot again for the stop stopping firing group.
‫Let me go to hello Kotlin.
‫And here I can use this general robot which is a fighting robot, and call the stop method run.
‫And again we have a new robot is created.
‫Changing the model, starting firing robot and stopping firing robot.
‫So these functions are working fine.
‫We are inheriting them from the robot actions interface.
‫In this example we learned about interfaces and abstraction in Kotlin.