Book Image

Programming Kotlin

Book Image

Programming Kotlin

Overview of this book

Quickly learn the fundamentals of the Kotlin language and see it in action on the web. Easy to follow and covering the full set of programming features, this book will get you fluent in Kotlin for Android.
Table of Contents (20 chapters)
Programming Kotlin
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface

Interface or abstract class


There is always a debate over using either an interface or an abstract class. Here are a few rules to follow when deciding which way to go:

  • Is-a versus Can-Do: Any type can inherit from one parent class only and multiple interfaces. If for the derived class B you can't say B Is-an A (A is the base type), don't use an interface but rather an interface. Interfaces imply a Can-Do relationship. If the Can-do functionality is applicable to different object types, go with an interface implementation. For example, for both FileOutputStream and ByteOutputpuStream (and any of the other sibling implementations available), you can say they have an Is-a relationship with java.io.OutputStream. Hence you will see that OutputStream is an abstract class providing common implementations to all objects that represent a writable stream. However, Autocloseable, which represents an object holding a resource that can be released when the close method is invoked, provides a Can-do functionality...