Design Pattern and Principles Flashcards

1
Q

Who said this?
“Design is not just how it
looks and feels like.
Design is how it works”

A

Steve Jobs

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

is the creation of experience

A

Design

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

Design is the ______ of the said creation and how well it’s organized

A

process

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

Design is the _____ i.e. the things we see hear, and feel

A

result

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

There is a definite meaning for design(T or F)

A

F (there is no)

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

Design is a plan for arranging _____ in such a way as best to accomplish a particular purpose.

A

elements

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

are typical solutions to commonly occurring problems in software design

A

Design petterns

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

Design patterns are like ____ _____that you can customize to solve a recurring design problem in your code

A

pre-made blueprint

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

Design Pattern is a specific piece of code, not a general concept for solving particular problems(T or F)

A

F (is not specific piece of code but a general concept)

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

Design Pattern and Algorithm are interchangeble(T or F)

A

F( Algo = cooking recipe; DP = Blueprint)
(Algo= define set of actions; DP= high-level desc of solution)

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

Sections that are usually present in patterm descriptions

A

Intent
Motivation
Structure
Code Exampe

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

_____ of the pattern briefly describes both the problem and the solution

A

Intent

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

____ further explains the problem and the solution the pattern makes possible

A

Motivation

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

_____ of classes shows each part of the pattern and how they are related

A

Structure

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

_____ ______ in one of the popular programming languages makes it easier to grasp the idea behind the pattern

A

Code example

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

The most basic and low-level patterns are often called _____

A

idioms

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

The most universal and high-level pattern are _____ ______. Devs can implement these patterns virtually in any language.

A

Architectural patterns

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

All patterns can be categorized by their ______ or ______

A

intent or purpose

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

3 main groups of pattern

A

Creational Pattern
Structural Pattern
Behavioral Pattern

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

provide object creation mechanisms that increase flexbility and reuse of existing code

A

Creational pattern

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

explain how to assemble objects and classes into larger structures, while keeping the structure flexible and efficient.

A

Structural pattern

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

take care of effective communication and the assignment of responsibilities between objects

A

Behavioral patterns

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

are typical solutions to common problems in object oriented design

A

Patterns

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

Who first described the concept of pattern

A

Christopher Alexander in his book A pattern Language

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

This book describes a language for designing the urban environment, the units this language are pattern

A

A Pattern Language: Towns, Building, Construction

26
Q

The four authors who picked up the Idea of patterns (EG, JV, RJ, RH)

A

Erich Gamma
John Vlissides
Ralph Johnson
Richard Helm

27
Q

Erich Gamma
John Vlissides
Ralph Johnson
Richard Helm
published a back, what is that book?

A

Design Pattern: Elements of Reusable Object-Oriented Software( The book by the gang of four)/ (the GOF book)

28
Q

Design patterns are a toolkit of ______and ______solutions to common problems in software design

A

Tried and Tested

29
Q

several universal principles of software design(3+2)

A
  1. Encapsulate What Varies
    1.1 Encapsulate on a method level
    1.2 Encapsulate on a class level
  2. Program to an interface not an implementation
  3. Favor composition Over Inheritance
30
Q

Identify the aspects of you application that vary and separate them from what stays the same; the main goal of this principle is to MINIMIS THE EFFECT CAUSE BY CHANGES.
With this, you spend less time getting the
program “afloat”, more time for you to
implement features.

A

Encapsulate What Varies

31
Q

in the principle, Encapsulate What Varies, you can isolate the part of the program that vary in ______ modules

A

independent modules

32
Q

Anticipate parts of you code that might need to change in the future.
if you knew that a part of your code may change during the program’s lifetime, you have to put it in a separate method.
This is to make sure that if ever that part of a code changes, it is now easier to isolate the problem without ruining the entire code.

A

Encapsulate on a method level

33
Q

Overtime you might want to add more responsibilities to a method which used to do a simple thing.
Adding another method to help the first method may help, but this may blur the primary responsibility of the containing class itself.
Extracting the method to another class might make things much more clear and simple.

A

Encapsulate on a class level

34
Q

Depend on abstraction, bot concrete classes.
Make sure that you design is flexible: the code can be extended without breaking existing code.
This can allow classes to collaborate, adding further functionality and flexibility to you code.
This through abstract classes and polymorphism

A

Program to an interface, not an implementation

35
Q

Caveats of inheritance:

A

A subclass can’t reduce the interface of the superclass
When overriding method you need to make sure that the new behavior is compatible with the base one.
Inheritance breaks encapsulation of the superclass
Subclasses are tightly coupled to superclass
Trying to reuse code through inheritance can lead to creating parallel inheritance hierarchies.

36
Q

an alternative to inheritance is ______

A

composition

37
Q

if inheritance represents the “IS-A” relationship, composition represents the “_______ relationship.

A

HAS-A relationship

38
Q

You may also use a more relaxed variant of composition, which is called_______

A

Aggregation

39
Q

Is a mnemonic for five design principles intended to make software design more understandable, flexible and maintainable.

A

SOLID

40
Q

Who introduced the 5 SOLID Principles, and what book was it in?

A

Robert Martin
in his book
Agile Software Development, Principles, Patterns, and Practices

41
Q

SOLID stands for what?

A

Single Responsibility Principles
Open/Closed Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle

42
Q

A class should have just one reason to change.
Every class = single part func. + make encapsulated(hidden) by class

A

Single Responsibility Principles

43
Q

What is the main goal of SRP?

A

Reducing Complexity

44
Q

The main problem with SRP that when the program constantly grow and change. At some point classes become so ____ that you can no longer remember their details

A

big

45
Q

Classes should be open for extension but closed for modification
The main idea of this principle is to keep existing code from breaking when implementing features

A

Open/Closed Principle

46
Q

a class is ____ if you can extend it, produce a subclass and whatever you want with it– add new methods or fields, overrides base behavior, etc.

A

Open

47
Q

A class is ____ or _____ if it’s 100% ready to be used by other classes— its interface is clearly defined and won’t be changed in the future.

A

closed

48
Q

In OCP, instead of changing the code of the class directly, you can create a ______ and override parts of the original class that you want to behave differently.

A

Subclass

49
Q

When extending a class remember that you should be able to pass objects of the subclass in place of objects of the parent class without breaking the client code

A

Liskov Substitution Principle

50
Q

Who named LSP in 1987

A

Barbara Liskov

51
Q

Which work Barbara Liskov in 1987 did she defined LSP?

A

Data abstraction and hierarchy

52
Q

In LSP, when overriding a method, _____the base behavior rather than replacing it with something else entirely

A

extend

53
Q

LSP is critical when developing _____ and ____ because your classes are going to be used by other people whose code you can’t directly access and change.

A

Libraries and framework

54
Q

LSP has a set of formal requirements for subclasses and specifically for their methods

A
  1. Parameter types in a method of a subclass should match or be more abstract than parameter types in the method of the superclass
  2. The return type in a method of a subclass should match or be a subtype of the return type in the method of the superclass.
  3. A method in a subclass shouldn’t throw types of exceptions which the base method isn’t expected to throw
  4. A subclass shoudn’t strengthen pre-conditions
  5. shoudlnt weaken post conditions as well
  6. Invariant of a superclass must be preserved
  7. A subclass shouln’t change values of private fields of the superclass
55
Q

Clients shouldn’t be forced to depend on method they do not use.
Make interface narrow enough
“fat” interface = not want
dont cram unrelated methods
Break into several more refined interface

A

Interface Segregation Principle

56
Q

High-level classes shouldn’t depend on low-level classes. Both should depend on abstractions.

A

Dependency Inversion Principle

57
Q

Abstraction should dependent on details(T or F)

A

F should not depend on details

58
Q

Implement BASIC OPERATIONS such as working with a disk, transferring data over a network, connecting to a database, etc.

A

Low-level classes

59
Q

contain COMPLEX BUSINESS LOGIC that directs low-level classes to do something

A

High-level classes

60
Q
A