theory Flashcards

(81 cards)

1
Q

The word design is

A

both a verb (the process of designing) and a noun (outcome of the process) (this creates ambiguity around the word design)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Textbook definition of design:

A

the construction of abstractions of data and computation and the organization of these abstractions into a working software application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Design Space:

A

an n-dimensional geometric space where each dimension corresponds to a design quality attribute (understandability, reusability, ease of implementation)
Space of possible solutions
Space of acceptable solutions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what kind of process is design?

A

highly heuristic process (iterative problem solving, guided by principles and design techniques)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Ignorant surgery:

A

the problem of modifying code in a way that does not respect the original structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Design context:

A

a specific set of requirements and constraints within a domain in which a design solution must be formed and integrated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Sustainability:

A

the idea of having design decisions be self-evident in code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Process model:

A

describes how the different steps required to create a system are organized.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Waterfall software processing model

A

very planning heavy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Agile development:

A

more organic approach

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Sustainability:

A

the idea of having design decisions be self-evident in code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

practice:

A

well understood way of doing something to achieve a certain benefit
Ex) version control (keep track of changes to software development artifacts)
Ex) pair programming

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Refactoring:

A

improving the design without changing the functionality

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Technical debt

A

when programmers implement quick and dirty solutions that don’t align properly with the existing design

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When decomposing a system into distinct, manageable abstractions,

A

the abstractions have to be isolated from teacher (not dependent on each other).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Encapsulation:

A

enclose something as if it were in a capsule
Ex) a nut is encapsulated in its shell and the shell serves to protect the nut. The shell is synonymous with an interface. Encapsulation makes it easier to understand code in isolation and it’s easier to change one part of the code without breaking anything.
Ex)deck of cards where there are 52 cards and each card can be represented by its suit and rank

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Object state:

A

built in characteristics or properties of an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

State diagram:

A

models the behavior of a single object, specifying the sequence of events that an object goes through during its lifetime in response to events

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

NULL OBJECT pattern:

A

encapsulate the absence of an object by providing a substitutable alternative
Consider declaring instance variables final whenever possible;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

singleton pattern

A

Consider using the SINGLETON pattern for classes that should yield only one instance of a stateful object, while providing a global access point to this instance.
ex) A country can have only one official government.
Remember that additional data can be attached to instances of inner classes, ei-ther in the form of a reference to an instance of an outer class, or as copies of local variables bundled in a closure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

FLYWEIGHT pattern:

A

If objects are not designed to be unique, override the equals and hashCode

methods; if objects should be unique, consider using the FLYWEIGHT pattern to

enforce uniqueness
FLYWEIGHT pattern: lets you fit more objects into the available amount of RAM by sharing common parts of state between multiple objects instead of keeping all of the data in each object. Flyweight objects are immutable. This means that they cannot be modified once they have been constructed. We use a HashMap that stores reference to the object which have already been created, every object is associated with a key.
In browsers, we can use an image in multiple places in a webpage. Browsers will load the image only one time, and for other times browsers will reuse the image from cache.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

composite pattern

A

If a design problem requires structures that change at run-time or can be combined, consider building the structures by combining objects, as opposed to defining new classes for each possible structure.
Use the C O M P O S I T E when you need to manipulate collections of objects the same way as single (“leaf”) objects. It lets you compose objects into tree structures and then work with these structures as if they were individual objects.
ex) Armies of most countries are structured as hierarchies.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

decorator pattern

A

Use the DECORATOR when you need to add functionality to certain objects, while being able to use them in place of “regular” objects. It lets you attach new behaviors to objects by placing these objects inside special wrapper objects that contain the behaviors.
The COMPOSITE and DECORATOR can be combined easily, especially if they share the same component type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

respect the Law of Demeter:

A

a module should not know about the inner details of the objects it manipulates

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Command pattern:
Command pattern: You need a command to have a life span independent of the original request, or if you want to queue, specify and execute requests at different times. paper order serves as a command. It remains in a queue until the chef is ready to serve it. The order contains all the relevant information required to cook the meal. It allows the chef to start cooking right away instead of running around clarifying the order details from you directly.
26
Prototype pattern:
lets you copy existing objects without making your code dependent on their classes.
27
polymorphic copying (cloning)
Use polymorphic copying (cloning) to make copies of objects whose concrete type is not known at compile time. If the type is known at compile time, favor the simpler technique of copy constructors; Polymorphic copying can also be used as a way to create fresh instances of objects whose type is not known at compile time, a technique called the PROTOTYPE pattern.
28
Inheritance:
one object acquires all the properties and behaviors of a parent object. Solution to code reuse and extensibility. Whereas inheritance derives one class from another, composition defines a class as the sum of its parts.
29
downcasting or type refinement
is the act of casting a reference of a base class to one of its derived classes. (when sub class type is converted into super class type). We want to avoid downcasting and use polymorphism instead.
30
Template method pattern:
defines the skeleton of an algorithm in the superclass but lets subclasses override specific steps of the algorithm without changing its structure.
31
final method
If there is no obvious scenario for overriding a method, consider declaring it final. Similarly, if there is no specific reason for a class to be extensible using inheritance, consider declaring it final.
32
Liskov Substitution Principle:
Liskov Substitution Principle: objects of a superclass shall be replaceable with objects of its subclasses without breaking the application.
33
@Override annotation:
indicates that the child class method is over-writing its base class method.
34
Overloading
occurs when two or more methods in one class have the same method name but different parameters.
35
Lambda expressions:
an anonymous function (a function with no name)
36
To emphasize flexibility and extensibility in your design,
use library functional interfaces to define function types; to emphasize design constraints and intent, use application-defined functional interfaces
37
A collection
A collection is an object that can hold references to other objects. Can use a collector object to accumulate the result of stream operations.
38
Supplier
functional interface which does not take any argument and produces result of type T
39
first-class functions:
first-class functions: functions are treated as variables.
40
Map abstraction
refers to the process of explicitly defining and representing real-world features on a map
41
Inversion of control:
``` invert different kinds of controls (additional responsibilities a class has, other than its main responsibility) in object-oriented design to achieve loose coupling. Inversion of control is the principle behind the OBSERVER pattern suppose you drive a car to your work place. This means you control the car. The IoC principle suggests to invert the control, meaning that instead of driving the car yourself, you hire a cab, where another person will drive the car. Thus, this is called inversion of the control - from you to the cab driver. You don't have to drive a car yourself and you can let the driver do the driving so that you can focus on your main work. ```
42
Loose coupling
is an approach to interconnecting the components in a system or network so that those components, also called elements, depend on each other to the least extent practicable.
43
Dependency inversion: stream
High-level modules, which provide complex logic, should be easily reusable and unaffected by changes in low-level modules is a sequence of objects that supports various methods which can be pipelined to produce the desired result.
44
Single responsibility principle:
A class should have one, and only one, reason to change.
45
open/closed principle:
Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.
46
Interface segregation principle:
Clients should not be forced to depend upon interfaces that they do not use.
47
Adapter pattern:
allows objects with incompatible interfaces to collaborate.
48
Visitor pattern:
lets you separate algorithms from the objects on which they operate.
49
Handlers
observers of objects
50
There are two strategies for exchanging data between a model and its observers:
push or pull;
51
Callback method:
callback is something that you pass to a function, which tells it what it should call at some point in its operation.
52
event- based programming:
the flow of the program is determined by events such as user actions (mouse clicks, key presses)
53
OBSERVER pattern:
lets you define a subscription mechanism to notify multiple objects about any events that happen to the object they’re observing.
54
Avoid PAIRWISE DEPENDENCIES
(whenever the user changes the number in a panel, this panel directly contacts all other panels and up- dates their view of the number) because they create high coupling and low extensibility.
55
Model–View–Controller decomposition:
an application consist of a data model, presentation information, and control information. The pattern requires that each of these be separated into different objects.
56
An interface to a class consists of
the methods of that class that are accessible (or visible) to another class. By extension, the interface to an object is the set of methods that can be called on the object.
57
Factory Method:
provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created. Factory Method is about having different ways of creating something.
58
Strategy design pattern:
``` use if part of your design requires supporting an interchangeable family of algorithms. The Strategy pattern suggests that you take a class that does something specific in a lot of different ways and extract all of these algorithms into separate classes called strategies. Strategy pattern is about having different ways of doing something. Imagine that you have to get to the airport. You can catch a bus, order a cab, or get on your bicycle. These are your transportation strategies. You can pick one of the strategies depending on factors such as budget or time constraints. ```
59
ITERATOR design pattern:
Use iterators to expose a collection of objects encapsulated within another with- out violating the encapsulation and information hiding properties of this object. It’s, basically, something or someone who you can ask for the next available item in a set of items, and who can give you access to all those items in the set. ex) A waitress in the restaurant will be iterating through your meal choices as you are having a five course meal, for example.
60
Lambda expressions are a form of
anonymous functions.
61
Class diagrams represent
a static, or compile-time, view of a software system.
62
Composition -
I own an object and I am responsible for its lifetime. If department is canceled, then the class program is also canceled
63
Association -
I have a relationship with an object
64
Aggregation -
``` object is standalone and can exist even if the object of owning class is dead If department is canceled, teachers still exist ```
65
function objects:
any object that can be called as if it is a function
66
Abstract methods:
methods that don’t have an implementation
67
Use interface types to
decouple a specification from its implementation if you plan to have different implementations of that specification as part of your design;
68
Define interfaces so that
each interface groups a cohesive set of methods that are likely to be used together; Organize interfaces as subtypes of each other to create flexible groupings of behavior; Use library interfaces, such as Comparable, to implement commonly expected behavior;
69
Decoupling:
two or more systems somehow work or are connected without being directly connected. interfaces provide a specification of the methods that it should be possible to invoke on the objects of a class. interface method declarations are a specification and not an implementation.
70
To tie a class with an interface, use the
implements keyword (creates a subtype relationship between the implementing class and the interface type) . This subtyping lets us use polymorphism.
71
Polymorphism:
ability to have different shapes.
72
Benefits of polymorphism are
loose coupling(code using a set of methods is not tied to a specific implementation of these methods) and extensibility(can easily add new implementations of an interface)
73
Comparable interface
defines a piece of behavior related specifically to the comparison of objects, in the form of a single int compareTo(T) method. It should return 0 if the implicit argument is the same as the explicit argument, a negative integer if it should come before, and a positive integer if it should come after. It's possible to assign a value to a variable if the value is of the same type or a subtype of the type of the variable.
74
Enumeration:
a class that represents constants (unchangeable). They are globally available constants (static fields). The constants have a unique reference to an object of the class that corresponds to the enumerated value.
75
Primitive obsession antipattern:
the tendency to use primitive types to represent other abstractions. Can avoid falling into this antipattern by using enumerated types.
76
Object:
a mechanism to group variables together and access their values through the process of dereferencing
77
Access modifiers:
Java keywords that control what parts of the code can access program elements. Helps us control the visibility. They express the intent of the developer about how certain structures are meant to be used and support automatic enforcement of the stated intent through compilation. Public members are visible anywhere Private members are only visible within the scope of the class
78
To achieve encapsulation
use the narrowest possible scope for class members. Instance variables should be private.
79
Scope:
lexical region that acts as a boundary for variables. Define scope with a curly brace
80
primitive vs. reference variables
primitive variables store the actual values, whereas reference variables store the addresses of the objects they refer to.
81
3 ways reference to a private structure can escape the scope of its class
1. Return a reference to an internal object Inappropriate intimacy antipattern: when classes spend too much time delving into each others’ private parts. 2. Store an external reference internally. This reference would become shared by the client code. 3. Leak references through shared structures . However, leaking a reference to an internal object is harmless if the object is immutable.