Access over 20 million homework & study documents
search

CS 226T Programming to An Interface Paper

Content type

User Generated

Subject

Programming

Type

Research Paper

Rating

Showing Page:
1/4
Kodie Turner
CS226T
12/1/2019
Programming to an interface is developing code abased on the interface provided.
Interface is a set of methods with method signatures and without the actual
implementations. An interface outlines the behavior of the object with a set of methods.
Programming to an interface helps you to write easy to maintain programs and
programs that are easy to extend. Programming to interface shields the programs
against changes to the actual implementations.
On the other hand, programming to an implementation means that developing the
actual code implementation of a particular object behavior based on the internal
implementations of the object. The main disadvantage is that programs fail when
internal implementations of the object change. There is no shield in this programming
practice.
Maintainability
Program against interface rather than actual implementations to make the code more
maintainable to the changes in the implementations. For example, consider below
scenario

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/4
Interface DisplayDevice
A Computer can display to ComputerMonitor or ProjectorScreen.
ComputerMonitor can implement DisplayDevice interface. Similarly, ProjectorScreen
can implement DisplayDevice. Computer program should be coded against
DisplayDevice interface to work with actual implementations at runtime.
Extending classes:
Example of Car object and CarInterface. The CarInterface with methods
public interface CarInterface {
public void drive();
public void brake();
public void accelerate();
public void print();
}
New implementations can be easy to extend by creating new classes that implement
the interface. Let’s take two Car classes Ford150 and TeslaCyberTruck .
public class Ford150 implements CarInterface {
….

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/4

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 4 pages?
Access Now

Unformatted Attachment Preview

Kodie Turner CS226T 12/1/2019 Programming to an interface is developing code abased on the interface provided. Interface is a set of methods with method signatures and without the actual implementations. An interface outlines the behavior of the object with a set of methods. Programming to an interface helps you to write easy to maintain programs and programs that are easy to extend. Programming to interface shields the programs against changes to the actual implementations. On the other hand, programming to an implementation means that developing the actual code implementation of a particular object behavior based on the internal implementations of the object. The main disadvantage is that programs fail when internal implementations of the object change. There is no shield in this programming practice. Maintainability Program against interface rather than actual implementations to make the code more maintainable to the changes in the implementations. For example, consider below scenario Interface DisplayDevice A Computer can display to ComputerMonitor or ProjectorScreen. ComputerMonitor can implement DisplayDevice interface. Similarly, ProjectorScreen can implement DisplayDev ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Just what I needed…Fantastic!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4