Interface (java) - INTRODUCTION In this lab session our...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
INTRODUCTION In this lab session our main goal is to get familiar with the interfaces and study it. And also through this lab session we will be able to learn how the interfaces work and how to use them for code reusability. After we go through the lab exercises and home work exercises in this lab session we might be able to understand how to implement a necessary interface to a given scenario and the basic concepts behind it. Interface An interface in the Java programming language is an abstract type that is used to specify an interface (in the generic sense of the term) that classes must implement. Interfaces are declared using the interface keyword , and may only contain method signatures and constant declarations (variable declarations that are declared to be both static and final). An interface may never contain method definitions The Java programming language has two features supporting subtype polymorphism: class extension and interface1 implementation. If a class extends another (possibly abstract) class, it inherits all the members of that class; its type is considered a subtype of the extended class’s type; and it implicitly shares an interface with the extended class. If a class implements an interface, it must provide an implementation of all the methods of the interface, and its type is considered a subtype of the interface’s type. Java does not support multiple inheritances, so a class may not extend more than one class, but a class may implement more than one interface. Thus class extension can be used for subtype polymorphism and code reuse, but not multiple sub typing; interface implementation. Separating the Interface from the Implementation Object composition offers another way to achieve reuse without the tendency toward tight coupling. Object composition is based on black-box reuse , in which implementation details of a class are never revealed to the client. Clients know only about an available set of requests (the what). Objects never expose internal details of the response (the how). Black-box reuse is based on formal separation of interface and implementation. This means the interface becomes a first-class citizen. An interface is an independent data type that is defined on its own. This is an evolution of classic OOP, in which a public interface is defined within the context of a class definition. At this point, you are probably thinking that this is all pretty vague. You're asking yourself, "What exactly is an interface?" Unfortunately, it's hard to provide a concise definition that conveys the key concepts of an entirely new way to write software. An interface can be described in many ways. You can get up to speed pretty quickly on the syntax for defining, implementing, and using interfaces. However, the implications that interfaces have on software design are much harder for the average programmer to embrace. Learning how to design with interfaces usually takes months or years.
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern