-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterfaces-abstract-classes-notes.txt
More file actions
30 lines (24 loc) · 1.28 KB
/
Copy pathinterfaces-abstract-classes-notes.txt
File metadata and controls
30 lines (24 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Interfaces & Abstract Classes - Cheat Sheet
### Both of Them
Think of an `interface` or an `abstract class` like a **set of rules/requirements** for the class that uses them.
`public interface truck` (rules) | `public class Car implements truck` (follows all the rules)
---|---
generateHorsepower() | public void generateHorsepower()
burnFuelEfficiently() | public void burnFuelEfficiently()
turnOnAc() | public void turnOnAc()
⬆ _(here's what should exist️)_ |⬆ _(here's the actual function written out when this interface is implemented)_
## Abstract Class (extends)
- Good for declaring non-public members (interfaces only allow public)
- Easier to add methods in the future without breaking functionality
- Can partially implement functionality (write out the methods), whereas you can't implement ANY functionality in an interface.
- **Contains**
- instance and static variables.
- instance and static constants.
- instance and static methods.
## Interface (implements)
- Good for providing common functionality to unrelated classes
- Good when we want to implement multiple interfaces
- If we're designing small, concise bits of functionality, use interfaces. If we're designing large functionality, use an abstract class.
- **Contains**
- abstract methods.
- static constants.