CS 18000 Lecture 30: CS 18000 - Interfaces

32 views2 pages
CS 18000: Chapter 10 - Interfaces
1. What are interfaces?
a. They allow us to create a collection of methods to guarantee a class’ interaction.
2. Why do I need Interfaces?
a. From CS, you know that objects define their interaction with the outside world
via methods they expose. Methods form the object's interface
with the outside
world. For, the power button on your TV is an interface between you and the
electrical wiring on the other side of its plastic casing. You press the "power"
button to turn the television on and off.
b. In more layman’s terms, an interface is a blueprint of methods that every is
shared among all of the classes. For example, every character on The Big Bang
Theory (excluding Penny) has some kind of high-level degree.
3. How do we execute them?
a. We do so by having “implement” in our class name, such as public class Sheldon
implements TheBigBangTheory
b. Implementing an interface allows a class to become more formal about the
behavior it promises to provide. Interfaces form a contract between the class
and the outside world, and this contract is enforced at build time by the
compiler. If your class claims to implement an interface, all methods defined by
that interface must appear in its source code before the class will successfully
compile.
4. @Override
a. Why do we use this?
i. 1) So that you can take advantage of the compiler checking to make sure
you actually are overriding a method when you think you are. This way, if
you make a common mistake of misspelling a method name or not
correctly matching the parameters, you will be warned that you method
does not actually override as you think it does.
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Document Summary

For, the power button on your tv is an interface between you and the with the outside electrical wiring on the other side of its plastic casing. You press the power button to turn the television on and off. b. In more layman"s terms, an interface is a blueprint of methods that every is shared among all of the classes. For example, every character on the big bang. Theory (excluding penny) has some kind of high-level degree: how do we execute them, we do so by having implement in our class name, such as public class sheldon implements thebigbangtheory b. Implementing an interface allows a class to become more formal about the behavior it promises to provide. Interfaces form a contract between the class and the outside world, and this contract is enforced at build time by the compiler. @override public int getlikes() { return numlikes; public interface friendable {

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents