Procedural Abstraction
concept in cs where details are hidden within a procedure or function, allowing users to focus on high-level operations
Can be done within:
- An expressionm
- A statement
How does Procedural Abstraction can be done ?
Can be done by means of methods that:
- Operate on parameter objects
- Return a primitive value, object, or void
What is Modularisation for data
Combining variables of primitive types that frequently occur together into a single abstraction, instead of handling them separately
How can Modularisation for data can be done?
Grouping can be accomplished by String, array, and class, but only class can introduce a new name for the type
Top-down Design
Bottom-up Design
Enumerations
Operations for Enumeration T
Records
Provide a concise way to declare unchangeable data-carrying classes by automatically generating standard methods such as constructors, getters, equals(), hashCode(), and toString() based on the class’s fields
Featues of Records
Abstract Data Type
A high-level description of a set of operations that can be performed on a certain type of data, along with the constraints or properties that these operations must adhere to.
Abstract Data Classes
Public invariants in ADTs
The properties or conditions that must be true for the data type’s public methods to function correctly (kinda like robustness)
Interfaces
Interfaces define a collection of method headers with contracts
Can define constants with public static final
Can have default method implementations but still no instance variables
Somewhat like a class with abstract methods but a class can implement one or more interfaces via implements by implementing each of the methods in the interface(s)
Interfaces can be viewed as a type; its values are the values of all classes that implement the interface
Interfaces vs. Abstract Classes
ADTs as specification
abstract classes and interfaces can both be used to hold just the specification of a class, leaving the actual implementation to the classes that extend/implement them
ADT implementation Components for values
ADT implementation Components for Operations
Polymorphisms
The ability of objects of different classes to be treated as objects of a common base class
Primitive vs. class type variables
Liskov Substitution Principle (LSP)
Let U be a subclass of T.
Type U is called a subtype of type T when:
- In each place where an object of type T can be used, you can substitute an object of type U without affecting the correctness of the program
A subtype is not only syntactically a substitute (it compiles), but also semantically (it works).
Strategy Design Pattern
Problem:
Accommodate multiple implementations of the same method by allowing selection at runtime.
Solution:
- Put specification of method in (abstract) class or interface
- Put implementations in subclasses of specification type
- Declare variable with specification type
Assign to variable an object of an implementation type
Intent of the Singleton Design Pattern
Solution of the Singleton Design Pattern: