Facts about Patterns Flashcards

(23 cards)

1
Q

True or False:

Patterns enable the re-use of an idea but not the re-use of code

A

True

Patterns describe logic and structure

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

Patterns form a vocabulary for software design

A

True
Vocab = words. Patterns allow you to give names to ways of doing things. Makes it easy for humans to understand and remember a standard way of doing things

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

A pattern is a Problem-Solution pair in a context

A

True

Patterns are reusable solutions to common problems in a given context

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

True or False:

Patterns help improve developer communication

A

True
If the dev’s all know the patterns, they can say “ yo use this pattern” or “ ye I used that pattern” rather than explaining each part of the code and how it works

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

Most of the common design patterns are object-oriented

A

True

Explains itself, because OO is common

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

Whether or not you are using design patterns for a project, being unfamiliar with patterns is a disadvantage for a team member

A

True
Because patterns make it easier to understand code and make it efficient. If someone does not know what pattern you have used then they are disadvantaged

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

Integrating patterns into a software development process is a human-intensive activity

A

True

Humans have to actively integrate patterns

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

A pattern describes a common programming problem and its solution

A

True

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

The Gang of Four book has become the de-facto standard pattern text

A

True

GoF is popular and good, so most dev’s like to use it

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

Gang of Four refers to the 4 main types of patterns

A

False

Gang of Four refers to the 4 authors

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

GRASP is a common Architectural Pattern

A

False

It is a set of design patterns. MVVC/ MVC and Client/Server are architectural patterns

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

Patterns enable the re-use of code

A

False

It enables the re-use of an idea

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

Consider the following C# code segment. The address-details “data clump”(postcode and city) is used in other parts of the program as well and should be factored out.

What refactoring do you suggest?

public class clsCustomer
{
   private string _Name;
   private string _PostCode;
   private string _City;

public string Name { get { return _Name; } }
public string PostCode { get { return _PostCode; } }
public string City { get { return _City; } }
}

A

Extract Class

is the combination of the Move Method and the Move Field

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
Change the code so that it works as before:
   1. Write the new code for the clsCustomer class after the change
public class clsCustomer
{
   private string _Name;
   private string _PostCode;
   private string _City;

public string Name { get { return _Name; } }
public string PostCode { get { return _PostCode; } }
public string City { get { return _City; } }
}

A

public class clsCustomer
{
private string _Name;
private clsAddressDetails_AddressDetails;

public string Name
{
get { return _Name; }
}

   public clsAddressDetails AddressDetails 
   { 
      get { return _AddressDetails; } 
   }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

2: Write the code for the clsAddressDetails class:

public class clsCustomer
{
private string _Name;
private clsAddressDetails_AddressDetails;

public string Name 
{
   get { return _Name; } 
}
    public clsAddressDetails AddressDetails 
    { 
       get { return _AddressDetails; } 
    }
 }
A

public class clsAddressDetails
{
private string _PostCode;
private string _City;

public string PostCost { get { return _PostCode } }
public string City { get { return _City } }
}

Notice that although there are changes, the clsCustomer class doesn’t change cause the public facade of clsCustomer is exactly the same. Only internal changes have been made.

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

Duplicated Code:

  1. Why is it problematic?
A
  1. Why is it problematic?

a.) If two or more people write similar code in the same program, this will cause 2 parts of code to work the same job.
Duplicated code means that if that code changes, it needs to change in both places, so it adds size, complexity, and makes it harder to maintain.

17
Q

Duplicated Code:

  1. How can it be fixed?
A
  1. How can it be fixed?
    a. ) Extract Method - replace duplicate code with a method made from the repeating code. (followed up with pull-up field for the fields used in the method that your pulling)
    b. ) Extract Superclass if that’s impossible, Extract class in one class and use new component in the other
18
Q

Feature Envy:

  1. Why is it problematic?
A
  1. Why is it problematic?
    a. ) Feature Envy comes in when an object is accessing properties that do not belong to it.

Basically, if class A is calling lots of methods/ fields from class B more than from itself, maybe the methods calling object B’s methods/fields should belong in object A instead of object B

b.) Dis-organized code

19
Q

Feature Envy:

2.) How can it be fixed?

A
  1. How can it be fixed?
    a. ) Move Field - Move the field to the appropriate class where it is used
    b. ) Move Method - Take the whole method and move it to a different class

OR

c.) Extract Method - Take a piece of code out of a method and in this case place it as its own method in a different class

20
Q

Name 5 pattern names from the “Fundamental” Category

A

a. ) Information Expert
b. ) Pure Fabrication,
c. ) Low Coupling,
d. ) Don’t talk to strangers - law of Demeter
e. ) Polymorphism - protected variations
f. ) Cohesion
g. ) Creator
h. ) Controller
i. ) Indirection
j. ) Delegation
k. ) Interface
l. ) Immutable
m. ) Marker Interface

21
Q

Name 4 pattern names from the “Behavioural” Category

A

a. ) Strategy
b. ) Template Method
c. ) Memento
e. ) Observer
f. ) Command Action Transition
g. ) State Objects for States
h. ) Chain of Responsibility
i. ) Interpreter
j. ) Iterator Enumerator
k. ) Mediator
l. ) Visitor

22
Q

Name 2 pattern names from the “Creational” Category

A

a. ) Singleton
b. ) Factory Method - virtual constructor
c. ) Prototype,
d. ) Builder
e. ) Abstract Factory Kit
f. ) Lazy Initialization,
g. ) Object Pool

23
Q

Name 2 pattern names from the “Structural” Category

A

a. ) Adapter Wrapper
b. ) Facade
c. ) Proxy Surrogate
d. ) Bridge Handle / Body
e. ) Composite
f. ) Decorator Wrapper
g. ) Flyweight
h. ) Container