Software Designs 2

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/93

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

94 Terms

1
New cards

What is the main intent of the Proxy design pattern?

To provide a surrogate (placeholder) for another object to control access to it.

2
New cards

What is another name for the Proxy design pattern?

Surrogate.

3
New cards

Why might a web page use a proxy for images or videos?

To allow the page to load and be visible immediately while waiting for media content to load.

4
New cards

What problem does the Proxy pattern solve in programming?

It simplifies the implementation and avoids affecting other modules while controlling access to another object.

5
New cards

In the Proxy pattern, what is the role of the ImageProxy class?

It contains all the same methods as Image, performs placeholder behavior, and forwards calls to the actual Image if it exists.

6
New cards

What are the four types of proxies mentioned?

Remote proxy, virtual proxy, protection proxy, and smart reference.

7
New cards

What is a remote proxy?

A local object that represents a network object (e.g., placeholders for web resources).

8
New cards

What is a virtual proxy?

A proxy that creates expensive objects on demand.

9
New cards

What is a protection proxy?

A proxy that adds permission checks before allowing access to the object.

10
New cards

What is a smart reference in the context of the Proxy pattern?

A proxy that adds behavior such as counting accesses to the object.

11
New cards

What is the structure of the Proxy pattern?

It involves a Proxy and a Subject. The Proxy has an identical interface to the Subject and controls access to it.

12
New cards

What is the role of the Proxy class (ImageProxy)?

Maintains a reference to the real subject, controls access, and optionally creates or deletes it on demand.

13
New cards

What does the Subject interface define in the Proxy pattern?

A common interface for the RealSubject and Proxy so the Proxy can be used in place of the RealSubject.

14
New cards

What is the RealSubject in the Proxy pattern?

The actual object being represented by the proxy

15
New cards

What is the collaboration between Proxy and RealSubject?

The Proxy forwards requests to the RealSubject when appropriate.

16
New cards

What are the consequences of using the Proxy pattern?

Introduces indirection; remote proxies hide object location, virtual proxies manage creation, protection proxies enforce access control, and smart references add functionality.

17
New cards

What is the benefit of copy-on-write in the Proxy pattern?

Saves memory and computation by only copying/loading the object when it is actually needed.

18
New cards

Where is the Proxy pattern commonly used?

In web/remote object retrieval and rich text documents with embedded media.

19
New cards

How does the Proxy pattern differ from the Adapter pattern?

Adapters provide different interfaces, while Proxies control access and can add extra functionality.

20
New cards

How is a Proxy similar to a Decorator?

Both may have similar implementations, but Decorators add responsibilities whereas Proxies control access.

21
New cards

Where can additional reading on the Proxy pattern be found?

GoF (Gang of Four).

22
New cards

What is the main intent of the Command design pattern?

To encapsulate a request as an object.

23
New cards

What are alternative names for the Command pattern?

Action, Transaction

24
New cards

What problem does the Command pattern solve in UI systems?

It allows UI elements like buttons to make customizable requests to different receivers by assigning them commands.

25
New cards

What is the benefit of making requests into objects in the Command pattern?

These objects can be passed around, stored, or manipulated like any other object.

26
New cards

What is a common method in Command pattern classes and what does it do?

Execute(); it performs the command’s action.

27
New cards

What does a ConcreteCommand store to perform its task?

A reference to a Receiver (e.g., MenuItem, Document, etc.).

28
New cards

When should the Command pattern be used?

When you want to:

  • parameterize objects by actions

  • queue/execute requests later

  • support undo

  • log operations

  • use transactions

29
New cards

What makes the Command pattern suitable for implementing Undo functionality?

Command.Execute() can store the state before executing.

30
New cards

What is the structure of the Command pattern?

It includes Command, ConcreteCommand, Client, Invoker, and Receiver.

31
New cards

What is the role of the Command interface?

Declares the interface for all commands

32
New cards

What does the ConcreteCommand class do?

Binds a Receiver to an action and implements the Execute() method.

33
New cards

What does the Client do in the Command pattern?

Creates a ConcreteCommand and sets its Receiver.

34
New cards

What does the Invoker do in the Command pattern?

Stores commands and calls their Execute() methods when needed.

35
New cards

What does the Receiver do in the Command pattern?

Knows how to perform the requested operation.

36
New cards

What is a collaboration sequence in the Command pattern?

Client → creates ConcreteCommand → assigns Receiver → Invoker stores command → calls Execute() → command acts on Receiver.

37
New cards

What is a major consequence of using the Command pattern?

It decouples the object that invokes a request from the one that knows how to execute it.

38
New cards

How are Commands treated in object-oriented programming?

As objects, allowing features like subclassing and composition.

39
New cards

What is a composite command?

A command that iterates through a list of commands and calls Execute() on each one.

40
New cards

How does the Command pattern support extensibility?

New commands can be added without changing existing classes.

41
New cards

Where is the Command pattern commonly used?

UI callbacks (menus, buttons), database queries, delegates (in C++, C#, etc.).

42
New cards

What patterns are related to the Command pattern?

Composite (for composite commands)

Memento (to store command state for undos)

Prototype (commands can be cloned)

43
New cards

What is the intent of the Chain of Responsibility pattern?

To decouple the sender and receiver of requests.

44
New cards

What is a real-world example of the Chain of Responsibility pattern in UI?

A help system where hovering over different parts of the interface shows context-specific tooltips, and if no specific help is found, it shows help from a parent element.

45
New cards

How does the Chain of Responsibility pattern work?

A request is passed along a chain of handlers until one handles it; the sender doesn’t know who will handle it.

46
New cards

What two things must each object have to implement Chain of Responsibility?

An interface to handle requests and a reference to the next object in the chain (successor).

47
New cards

When should you use the Chain of Responsibility pattern?

When more than one object may handle a request, and you want to dynamically determine the receiver without specifying it.

48
New cards

What is the structure of the Chain of Responsibility pattern?

It includes a Handler, ConcreteHandler(s), and a Client.

49
New cards

What does the Handler do in the pattern?

Declares an interface for handling requests and may implement the link to the successor.

50
New cards

What does the ConcreteHandler do?

Handles requests it's responsible for, may access and forward to its successor if it can't handle the request.

51
New cards

What is the Client’s role in this pattern?

Initiates the Handle() request to a ConcreteHandler.

52
New cards

How do ConcreteHandlers collaborate in this pattern?

A ConcreteHandler may collaborate with itself or forward requests to its successor.

53
New cards

What is a key benefit of Chain of Responsibility?

Reduced coupling between sender and receiver.

54
New cards

What flexibility does Chain of Responsibility add?

You can change or add handlers without modifying the sender or affecting others in the chain.

55
New cards

What is a potential downside of using Chain of Responsibility?

The request might not be handled at all if no handler is appropriate, requiring null checking.

56
New cards

Where is Chain of Responsibility commonly used?

UI systems and graphics/game engines for input handling.

57
New cards

What pattern is Chain of Responsibility often used with?

Composite; in such cases, the parent components act like handlers’ successors.

58
New cards

What is the intent of the Visitor design pattern?

To represent an operation to be performed on existing classes, without changing those classes.

59
New cards

What challenge does the Visitor pattern solve in an image editor scenario?

It avoids multiple nested loops and duplicated code when saving shapes in different formats by separating operations from object structure.

60
New cards

How does the Visitor pattern avoid changing shape or format classes when adding new save formats?

By implementing each format as a Visitor subclass and allowing shapes to accept visitors.

61
New cards

What is the purpose of the Accept(Visitor v) method in ConcreteElement classes?

It calls a specific Visit method on the Visitor, allowing the Visitor to perform operations based on the element’s type.

62
New cards

How would a Circle use the Visitor pattern to support saving?

Circle implements Accept(Visitor), which calls Visitor.SaveCircle(this), allowing format-specific logic to be defined in Visitor subclasses like PNGVisitor.

63
New cards

Why is the Visitor pattern useful in the image editor example?

It allows new file formats to be added without changing the shape classes.

64
New cards

When should you use the Visitor pattern?

When you want to perform operations across a class structure without modifying the classes and you have many different operations to perform.

65
New cards

What does the Visitor interface declare?

Visit methods for each class of ConcreteElement in the object structure (e.g., VisitCircle, VisitText).

66
New cards

What does a ConcreteVisitor implement?

The specific operations for each type of element (e.g., PNGSaver implements SaveCircle, SaveText, etc.).

67
New cards

What is the role of the Element in the Visitor pattern?

Defines the Accept(Visitor v) operation.

68
New cards

What is the client’s role in the Visitor pattern?

Creates the ConcreteVisitor and initiates traversal of the object structure.

69
New cards

What is a major benefit of using the Visitor pattern?

Adding new operations is easy—just create a new Visitor subclass.

70
New cards

How does the Visitor pattern help organize code?

It groups related operations together in the Visitor rather than scattering them across many classes.

71
New cards

What is a drawback of the Visitor pattern when adding new types of elements?

Each new element type requires updates to every existing Visitor, which can be cumbersome.

72
New cards

Why is Visitor useful across class hierarchies?

It can operate on elements that don’t share a common parent class, allowing flexible traversal.

73
New cards

What is the main intent of the MVC pattern?

To decouple visual (UI) and state (data) classes in an application.

74
New cards

Why is decoupling important in UI applications?

It keeps code organized and allows for better maintenance and scalability by separating concerns.

75
New cards

In a bank terminal app, how can opening a deposit prompt be broken into MVC parts?

  • User presses button: Controller

  • UI is updated: View

  • Internal state changes: Model

76
New cards

What makes an application an MVC application?

UI code, state code, and input handling code are separated into View, Model, and Controller components.

77
New cards

Do all classes in an MVC application need to be strictly categorized into Model, View, or Controller?

No, but UI classes should not handle state or user interaction logic.

78
New cards

What is the role of the Model in MVC?

Stores the application state and logic; it's the source of truth for all on-screen data.

79
New cards

What is the purpose of the View in MVC?

Displays data from the Model to the user and presents a UI representation of the state.

80
New cards

Should the View interact with the Model directly?

No, it should only be updated by the Model indirectly and manipulated via the Controller.

81
New cards

What is the Controller’s role in MVC?

Handles user input, validates it, and manipulates the Model accordingly.

82
New cards

How do the MVC components collaborate?

  • Controller manipulates Model

  • Model updates View

  • User uses Controller and sees View

83
New cards

What is one benefit of decoupling the View and the Model?

You can have multiple views represent the same data (e.g., charts, lists).

84
New cards

What pattern is commonly used with MVC to keep Views in sync with Models?

Observer pattern.

85
New cards

What is the main intent of the Interpreter design pattern?

To interpret a grammar, such as those used in regular expressions or programming languages.

86
New cards

What is a grammar in the context of programming?

A set of rules that defines valid strings in a language, including rules for structure, tokens, and expressions.

87
New cards

What is a syntax tree?

A hierarchical tree structure built from grammar rules, used to represent the structure of a valid sentence or expression.

88
New cards

What is the role of repetition and recursion in grammars?

Repetition handles patterns like lists, and recursion allows an expression to include itself for complex nested structures.

89
New cards

How does a grammar help in interpreting or validating data?

It allows a system to check whether a string matches the rules (validation) or extract structured data from it (interpretation).

90
New cards

What is the purpose of the AbstractExpression class in the Interpreter pattern?

It defines the interface for interpreting text and is the base for all terminal and non-terminal expressions.

91
New cards

What is the difference between TerminalExpression and NonterminalExpression?

TerminalExpression interprets basic, literal symbols; NonterminalExpression interprets combinations of expressions (rules).

92
New cards

When should you use the Interpreter pattern?

When you need to interpret a simple language using a grammar and performance is not a critical concern.

93
New cards

What is the role of the Context class in the Interpreter pattern?

It holds global information needed by the expressions during interpretation, such as input strings or output objects.

94
New cards

What are some known uses of the Interpreter pattern?

Regular expressions, file readers, and compilers.