Interfaces Why do we use Interfaces?
5.4.2 Interfaces
An interface is a special kind of block containing method signatures and possibly constants only. Interfaces define the signatures of a set of methods without the body. Interfaces define a standard and public way of specifying the behavior of classes. They allow classes, regardless of their location in the class hierarchy, to implement common behaviors. Note that interfaces exhibit polymorphism as well, since program may call an interface method and the proper version of that method will be executed depending on the type of object passed to the interface method call. 5.4.3 Why do we use Interfaces? We need to use interfaces if we want unrelated classes to implement similar methods. Through interfaces, we can actually capture similarities among unrelated classes without artificially forcing a class relationship. Lets take as an example a class Line which contains methods that computes the length of the line and compares a Line object to objects of the same class. Now, suppose we have another class MyInteger which contains methods that compares a MyInteger object to objects of the same class. As we can see here, both of the classes have some similar methods which compares them from other objects of the same type, but they are not related whatsoever. In order to enforce a way to make sure that these two classes implement some methods with similar signatures, we can use an interface for this. We can create an interface class, lets say interface Relation which has some comparison method declarations. Our interface Relation can be declared as, public interface Relation { public boolean isGreater Object a, Object b; public boolean isLess Object a, Object b; public boolean isEqual Object a, Object b; } Another reason for using an objects programming interface is to reveal an objects programming interface without revealing its class. As we can see later on the section Interface vs. Classes, we can actually use an interface as data type. Finally, we need to use interfaces to model multiple inheritance which allows a class to have more than one superclass. Multiple inheritance is not present in Java, but present in other object-oriented languages like C++.5.4.4 Interface vs. Abstract Class
Parts
» | Komputasi | Suatu Permulaan
» Quality Focus Process Method Tools
» What is quality? How do we define quality?
» Software Quality Characteristics of a Well-engineered Software
» Software Quality Assurance Activities Formal Technical Reviews
» Types of Software Process Models
» Understanding Systems | Komputasi | Suatu Permulaan
» End-users Understanding People in the Development Effort
» What is documentation? Criteria for Measuring Usability of Documents
» Abstraction Encapsulation Review of Object-oriented Concepts
» Modularity Hierarchy Review of Object-oriented Concepts
» Project Assignment Object-oriented Process Model
» Modeling Activity Unified Modeling Language UML
» UML Baseline Diagrams Unified Modeling Language UML
» Requirements Engineering Concepts | Komputasi | Suatu Permulaan
» Inception Requirements Engineering Tasks
» Elaboration Negotiation Requirements Engineering Tasks
» Specification Validation Requirements Engineering Tasks
» Management Requirements Engineering Tasks
» Scenario Modeling Requirements Analysis and Model
» Requirements Model Validation Checklist
» InvoiceNumber : Numeric Here, an attribute named InvoiceNumber contains a numeric value.
» Ternary association which is a relationship of three or more objects of
» The Analysis Model Analysis Model Validation Checklist
» Requirements Traceability Matrix RTM
» Requirements Metrics | Komputasi | Suatu Permulaan
» The Design Model Design Engineering Concepts
» Describing the Package Diagram Developing the Architectural Design
» Software Architecture Validation Checklist
» Developing the Data Design Model
» Report Design Interface Design
» Forms Design Interface Design
» Basic Component Design Principles Component-level Design Guidelines
» Component Diagram Developing the Software Component
» Project Assignment Design Model Validation Checklist
» Mapping the Design Deliverables to the Requirements Traceability Matrix Design Metrics
» Creating the Data Design Model Creating the Interface Design Creating the Control Design
» Project Assignment Programming Standards and Procedures
» Using Pseudocodes Control Structure Guidelines Documentation Guidelines
» Implementing Packages | Komputasi | Suatu Permulaan
» Abstract Classes Implementing Controllers
» Interfaces Why do we use Interfaces?
» Interface vs. Abstract Class Interface vs. Class Creating Interfaces
» Relationship of an Interface to a Class Inheritance among Interfaces
» Implementing Java Database Connectivity JDBC
» AWT GUI Components Implementing the Graphical User Interface
» Layout Managers Implementing the Graphical User Interface
» Controlling the Version of the Software
» Introduction to Software Testing
» White-Box Testing Techniques Software Test Case Design Methods
» Black-Box Testing Techniques Software Test Case Design Methods
» Testing your Programs | Komputasi | Suatu Permulaan
» Test-driven Development Steps Test-driven Development Methodology
» Testing Java Classes with JUnit
» Testing the System | Komputasi | Suatu Permulaan
» Mapping the Software Testing Deliverable to the RTM Test Metrics
» Project Assignment Software Project Management
» Problem Identification and Definition
» The Project Team Structure Project Responsibility Chart
» Project Work Breakdown Structure WBS
» Work Breakdown Schedule Format
» Size-oriented Metrics- Lines of Codes LOC Function-Oriented Metrics: Function Points FP
» Project Estimations | Komputasi | Suatu Permulaan
» The Risk Table Risk Management
» Risk Identification Checklist Risk Management
» Baseline Software Configuration Tasks
» Writing the Project Plan Project Assignment Case Tools
Show more