-
Notifications
You must be signed in to change notification settings - Fork 48
Quick Guide To Abstraction
A quick summary of abstraction in oop and abstract classes from lecture 2 and 3. There is a TLDR at the bottom. Enjoy!
"Where similar functions are carried out by distinct pieces of code, it is generally beneficial to combine them into one by abstracting out the varying parts" by Benjamin C. Pierce
- Abstraction in OOP allows the programmer to hide all but the relevant data about an object in order to reduce the complexity and increase the efficiency of the program.
- Objects in OOP allow programmers to hide the internal implementation details in their objects and only call upon them the methods when needed.
An example of abstraction in java is the use of packages such as java.lang.math where you just need to know which methods of the package are available and which input parameters are needed to trigger a specific operation. But you don’t need to understand how this method is implemented and which kinds of actions it has to perform to create the expected result.
Abstract class in Java is similar to interface except that it can contain default method implementation. An abstract class can have an abstract method without body and it can have methods with implementation also.
- Abstract Classes cannot be instantiated as their main purpose
- If a class have abstract methods, then the class should also be abstract using abstract keyword, else it will not compile.
- If an abstract class doesn’t have any method implementation, it's better to use interface because java doesn’t support multiple class inheritance.
- The subclass of abstract class in java must implement all the abstract methods unless the subclass is also an abstract class.
An abstract class is mostly used to provide a base for subclasses to extend and implement the abstract methods and override or use the implemented methods in the abstract class. The goal of this is to allow for Inheritance and to make a class well defined by the abstract method. (Refer to slide 15 lecture note 3 for an example)
Abstraction can be achieved by using the abstract class to hide certain code implementations. Java Abstract class is used to provide common method implementation to all the subclasses or to provide a default implementation.
Peer Learning
Codecrunch Contributions
Piazza Contributions
Wiki Contributions
Guides
Setting Up Checkstyle
Setting Up Java
Setting Up MacVim
Setting Up Sunfire
Setting Up Unix For Mac
Setting Up Unix For Windows
Setting Up Vim
Setting up SSH Config
CS2030 Contents
Lecture 1 SummaryCompile-run vs Run-time Summary
Quick Guide To Abstraction
Generics and Variance of Types
Comparable vs Comparator
Summary of completable future
CS2030S Notes
ELI5 Optional.map vs Optional.flatMap
PECS Example Code
Java Collection Framework (Iterator)
Generic
Generic Type Parameter and Generic Wildcard
Calculator
Lambda-Expression
Single Abstract Method (SAM)
Method Reference
Functional Interfaces 2
Simple Usage of Sandbox
Associative-but-not-commutative
Higher Order function
Functional Programming
Calculator With Functor
Eager Evaluation VS Lazy Evaluation
Simple Usage of Lazy Evaluation
Lazy Evaluation for LazyList
Lazy Evaluation for BinaryTree
Stream
Parallel Stream
Optional
Simple Usage of Stream
Asynchronous Programming
Notes on CompletableFuture
Notes on CompletableFuture 2
Simple Usage of CompletableFuture
Mind Map
Exception Handling
Links
CS2030 Java Style Guide
CS2030 Javadoc Specification
JDK 11 Download Link
JDK 11 API Docs
Codecrunch
Piazza Forum