1 / 6

Understanding Java Interfaces in Software Engineering

In software engineering, establishing a "contract" between programming teams is crucial for seamless integration. This contract, known as an interface in Java, allows different groups to develop their code independently without knowledge of each other's implementations. For instance, in the context of a driverless car, automobile manufacturers and electronic guidance manufacturers adhere to a defined interface, enabling collaboration without direct dependencies. This principle extends to APIs, where one company can leverage complex software packages provided by another, utilizing public interfaces for interaction while keeping their implementations confidential.

vin
Télécharger la présentation

Understanding Java Interfaces in Software Engineering

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SampleAndroid App Chien-Chung Shen CIS, UD cshen@cis.udel.edu

  2. Java Interface • In software engineering, it is important for disparate groups of programmers to agree to a "contract" that spells out how their software interacts • Each group should be able to write their code without any knowledge of how the other group's code is written • Such a contract is termed interfacein Java

  3. Example of Driverless Car • Automobile manufacturers write software that operates the car • Electronic guidance instrument manufacturers make computer system that uses GPS and traffic info to drive the car • Neither group needs to know howthe other group's software is implemented as long as they adhere to the published interface

  4. An Example Java Interface • public interfaceOperateCar { // constant declarations, if any // methodsignatures intturn(Direction direction, double radius, double startSpeed, double endSpeed); intchangeLanes(Direction direction, double startSpeed, double endSpeed); intsignalTurn(Direction direction, booleansignalOn); intgetRadarFront(double distanceToCar, double speedOfCar); intgetRadarRear(double distanceToCar, double speedOfCar); } • Write a class that implementsthe interface • public class OperateBMW760i implementsOperateCar { // the OperateCar method signatures, with implementation intsignalTurn(Direction direction, booleansignalOn) { // code to turn BMW's LEFT turn indicator lights on // code to turn BMW's LEFT turn indicator lights off ....... } // other members, as needed -- for example, helper classes not // visible to clients of the interface }

  5. Interfaces as APIs • Interface is used as an Application Programming Interface (API) • One company sells a software package that contains complex methods that another company wants to use in its own software product – e.g. • One company sells a package of digital image processing methods to companies making end-user graphics programs • The image processing company writes its classes to implement an interface, which it makes public • The graphics company then invokes the image processing methods using the signatures and return types defined in the interface • While API is made public (to its customers), its implementation is kept as a closely guarded secret

  6. UI Events • Android provides listeners for events, such as click, touch, etc. • InterfaceTextWatcher – watch for text changes in edit text field • InterfaceOnClickListener– handle click event • ImplementTextWatcher and attachit to the edit text field where user is typing the text • Methods of TextWatcher will be invoked (used) as user changes the text

More Related