Objects, UML, and Java Flashcards
Two most popular programming languages in 1960s
COBOL, Fortran
Imperative Paradigm
COBOL and Fortran followed an imperative paradigm which broke up large programs into smaller programs called subroutines, which are like methods in Java.
Two new algorithms in the 1970s
Algol 68, Pascal
New idea of programming introduced in 1970s
Local Variables
Abstract Data Type
An abstract data type is a data type that is defined by the programmer and not built into the language. An abstract data type is essentially a grouping of related information that is denoted with a type. It was a way to organize data in a meaningful way.
These two programming languages provided a means to organize programs and allow developers to more easily create multiple but unique copies of their abstract data types.
C, Modula-2
The crucial concept that became popular in the 1980s
Object Oriented Design
The goal of object-oriented design is to:
- Make an abstract data type easier to write
- Structure a system around abstract data types called classes
- Introduce the ability for an abstract data type to extend another
Object Oriented Programming is a paradigm. What are the 3 programming languages founded based off objects?
Java, C++, C#
Abstraction
Abstraction is the idea of simplifying a concept in the problem domain to its essentials within some context. Abstraction allows you to better understand a concept by breaking it down into a simplified description that ignores unimportant details.
Rule Of Least Astonishment
The abstraction captures the essential attributes and behavior for a concept with no surprises and no definitions that fall beyond its scope. You don’t want to surprise anyone trying to understand your abstraction with irrelevant characteristics.
Encapsulation
Encapsulation forms a self-contained object by bundling the data and functions it requires to work, exposes an interface whereby other objects can access and use it, and restricts access to certain inside details.
Decomposition
Decomposition is taking a whole thing and dividing it up into different parts. Or, on the flip side, taking a bunch of separate parts with different functionalities and combining them together to form a whole. Decomposition allows you to further break down problems into pieces that are easier to understand and solve.
How does inheritance work?
We use repeated, common, and shared characteristics between 2 or more classes and factor them out into another class. There is a parent class (superclass) and a child class (subclass).
Generalization
Technique which let us apply a rule “Don’t Repeat Yourself” (DRY) to write programs that are capable of performing the same tasks but with less code. It makes code more reusable because different classes or methods can share the same blocks of code.
3 ideas in encapsulation in Java
- Bundle data, and functions that manipulate the data, into a self-contained object
- Expose certain data and functions of that object, which can be accessed from other objects
- Restrict access to certain data and functions to only within that object
Getter Methods
Getter Methods are methods that retrieve data, and their names typically begin with get and end with the name of the attribute whose value you will be returning.
Getters often retrieve a private piece of data.
Setter Methods
Setter Methods change data, and their names typically begin with set and end with the name of the variable you wish to set.
Setters are used to set a private attribute in a safe way.
Three types of relationships found in decomposition
- Association
- Aggregation
- Composition
Association
Association is “some” relationship. This means that there is a loose relationship between two objects. These objects may interact with each other for some time.
Aggregation
Aggregation is a “has-a” relationship where a whole has parts that belong to it. There may be sharing of parts among the wholes in this relationship.
The “has-a” relationship from a whole to the parts is considered weak. What this means is although parts can belong to the wholes, they can also exist independently.
Composition
Composition is an exclusive containment of parts, otherwise known as a strong has-a relationship. What this means is that the whole cannot exist without its parts. If it loses any of its parts the whole ceases to exist. If the whole is destroyed then all of its parts are destroyed too. Usually you can only access the parts through its whole. Contained parts are exclusive to the whole.
UML empty arrow
head: superclass (generalized classes)
tail: subclass (specialized classes)
Arrows should point upwards, as superclasses are always towards the top and subclasses are always towards the bottom.
In Java, a protected attribute or method can only be accessed by
- The encapsulating class itself
- All subclasses
- All classes within the same package
Polymorphism
When 2 classes have the same description of a behavior but the implementations of the behavior may be different. This is achieved in an interface.
Interface
declares method signatures, and no constructors, attributes, or method bodies.
What to look out for when using inheritance?
- Ask yourself: “Am I using inheritance to simply share attributes or behavior without further adding anything special in my subclasses?”
- Liskov Substitution Principle
- Java Collections Library - Are you using the right type of inheritance/decomposition?
Liskov Substitution Principle
This principle states that a subclass can replace a superclass, if and only if, the subclass does not change the functionality of the superclass.
Coupling
Calculates the complexity between a module and other modules
Three ways to identify the coupling of a module
- Degree
- Ease
- Flexibility
Degree
Degree is the number of connections between the module and others. With coupling, you want to keep the degree small. For instance, if the module needed to connect to other modules through a few parameters or narrow interfaces, then the degree would be small, and coupling would be loose.
Ease
Ease is how obvious are the connections between the module and others. With coupling, you want the connections to be easy to make without needing to understand the implementations of the other modules.
Flexibility
Flexibility is how interchangeable the other modules are for this module. With coupling, you want the other modules easily replaceable for something better in the future.
Cohesion
Cohesion represents the clarity of the responsibilities of a module.