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

Info iconThis 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. At its most basic level,
Background image of page 1

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

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

This note was uploaded on 10/30/2011 for the course MECHATRONI EN11ME2050 taught by Professor Perera during the Spring '11 term at Asian Institute of Technology.

Page1 / 16

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online