Analysis of real questions and answers in the morning for software designers in the first half of 2021 (5)

41, 42, 43. When UML state diagrams are used to model dynamic aspects of a system, class or use case, it is usually to model ( ). In the following UML state diagram, it is assumed that the active state is A, the event b=0 occurs and a>5, the occurrence condition is the transition condition from state c to state d ( ), D becomes the active state, and the relevant state diagram In the statement, the incorrect one is ( ).
insert image description here
1)
A. Vocabulary of the system
B. Reactive object
C. Activity flow
D. Object snapshot

2)
A. Once the exit action of state A is completed, or if the do action is currently executing, terminate the execution
B. Once all the actions of states A and B are completed
C. Once the ongoing state A is completed
D. Once the exit action of state B Finish

(
_
_
_ b=5) is called time event
D. The state is triggered by the event

Reference answer: BBD
answer analysis:

  • A state diagram shows a state machine emphasizing the flow of control from state to state.
  • A state machine is a behavior that describes the sequence of states an object goes through in response to events during its lifetime and its responses to those events.
  • A state is the sequence of states that an object goes through in response to events during its lifetime and its responses to those events.
  • Statecharts typically contain simple and composite states, transitions (events and actions).
  • When modeling the dynamic aspects of a system, class, or use case, it is common to use state diagrams to model reactive objects.
  • A reactive (or event-driven) object is one whose behavior is often best characterized by its reaction to events from outside its context. A reactive object is usually idle until it receives an event; when it receives an event, its response often depends on previous events; after the object reacts to the event, it becomes idle again, waiting next event. For such objects, we will look at the stable states of the object, the events that trigger transitions from state to state, and the actions that occur when each state changes.
  • A state nested in another state is called a substate (A and B in this question are substates), and a state containing substates is called a combined state (also called a superstate, and C is a combined state). When state C is completed, D will enter the active state when b=5[a>5]. The current state is A. When A is completed, it will enter state B. After state B is completed, combined state C will be completed.
  • A transition is a relationship between two states, indicating that the object will perform a certain action in the source state and enter the target state when a specific event occurs and a specific guard (guardian) condition is met. An action is an executable atomic operation that is uninterruptible and whose execution time is negligible. Transitions are triggered by events, not states are triggered by events.

44, 45, 46, 47. In stock trading, the stock broker (Broker) performs stock trading operations according to the stock operation instructions issued by customers, and the class diagram is designed as shown below. The design adopts the () mode to encapsulate a request as an object, so that the client can be parameterized with different requests; the request is queued or the request log is recorded, and the operation that can be revoked is supported. The () statement executes the operation interface. The pattern belongs to the () pattern, which applies to: ().
insert image description here

(1)
A. Command (Command)
B. Observer (Observer)
C. State (State)
D. Mediator (Mediator)

(2)
A.Operation
B.sellOperation/BayOperation/ViewOperation
C.Broker
D.Stock

(3)
A. Structural type
B. Structural object
C. Creation type
D. Behavioral object

(4)
A. An object must inform other objects, and it cannot assume who the other objects are
B. Abstract the action of specific execution to parameterize an object
C. The behavior of an object is determined by its state and must be determined at runtime according to State change behavior
D. An object refers to other objects and communicates directly with these objects, making it difficult to reuse the object

Reference answer: AADB
answer analysis:
insert image description here

  1. Simple factory pattern
    Purpose: Enter a symbol to manufacture different computing classes, the theme is to encapsulate the class
    Realization: The class that implements the unified interface is handed over to a factory for manufacturing
  2. Strategy mode
    Purpose: Input a type, you can get different results, the theme is to encapsulate various rules (strategies)
    implementation: the class that implements the unified interface (protocol) is handed over to a context management class
  3. Decoration mode
    Purpose: Extend other features on the original object.
    Realization: extract the original object into the first-level class (protocol), the second-level class inherits the first-level class, and the third-level inheritance second-level class is the decoration class. The original is called Component, and the decoration is called Decorator
  4. Proxy mode
    Purpose: The original object does not move, let the proxy object realize the function of the original object, the theme is to find someone to do things to
    achieve: abstract the proxy event, one implements the proxy event class, and then the proxy class also implements the event protocol class, and has The original object and event implementation class throw the original object to the specific implementation event class, which is equivalent to the proxy class completing the action of the original class
  5. Factory method pattern
    Purpose: A factory creates factories with different functions, and each factory does its own corresponding thing
    Realization: Abstract factory class and specific function template class, implement different factory classes and implement different template classes, and different factories return specific template classes
  6. Template method pattern
    Purpose: Write a template class, inherit and rewrite subclasses
    Realization: Abstract subclass characteristics, write template class
  7. Appearance mode
    Purpose: Collect the functions of different classes, and summarize the unified export of a class
    Realization: A class has all functional class references, and provides methods to turn the functional class into a unified export
  8. Builder mode
    Purpose: The commander rules the builder, and the builder provides different functional rules to combine into a complete system
    implementation: the commander class holds the builder class reference, abstracts the builder function, and the implementer implements different functions according to the builder agreement system
  9. Observer mode
    Purpose: A class listens to events, and a class notifies to do things. Achieve external changes and take corresponding actions internally.
    Realization: Subscribers are responsible for collecting and notifying listeners, and listeners make their own changes after getting information, so listeners abstract an update operation interface
  10. Abstract Factory Mode
    Purpose: The aggregate of several factories. The factories create different product implementations according to different protocol specifications
    : start with entities, such as user entities and SQL entities in the database, and then create these two entities, and then create abstract entities. The operation class, and then abstract the operation class factory, establish different entity operation class factories, the factory holds the operation class and returns, and finally realizes the factory to create the operation class, and the operation class operates the entity.
  11. State mode
    Purpose: An entity, recording the state in each case
    Realization: Abstract state according to the requirements of the entity, different state implementations
  12. Adapter mode
    Purpose: Adapt the function of a certain class into a specific function without changing it Realization
    : Abstract the function to be replaced, and then let the adapter implement the function, and the adapter holds the specific function class
  13. Memo mode
    Purpose: To back up attributes, sometimes attributes want to return to a node
    to achieve: extract the attributes to be backed up into classes, these attributes must be on the main class and can be changed, and the management class is responsible for saving the backup data. It is convenient for the main class to call the attribute value of the management class at that time when needed
  14. Combination mode
    Purpose: Hierarchical distribution, just like the hierarchical relationship of classes in OC, child nodes are always combined into a big tree
    Implementation: Abstract composition interface protocol, both parent and child components implement this interface, and the parent component contains subcomponents
  15. Iterator mode
    Purpose: Relationship processing between collection classes and traversal classes
    Implementation: Abstract collection classes and abstract traversal classes, so that different collections (List, Set, Array) and traversal class loop methods can be implemented
  16. Singleton mode
    Purpose: There is only one memory class in the whole project Implementation
    : Memory is static, dispatch_once is initialized once
  17. Bridge mode
    Purpose: The main class can use the mode to extend the function without changing the original function
    Realization: The abstract main body agreement, the implementation class contains the reference of the functional class implemented in the concrete, the abstract function class contains the functions required in the main body, and the implementation class can be partially realized
  18. Command mode
    Purpose: the requester orders the requestee to do something Realization
    : the requester publishes information, the requestee receives information, information is an entity class, information processing is a specific entity class, information is diverse and can be abstracted , so both the requester and the requestee hold the information class, and there is excetue in the information
  19. Responsibility Mode
    Purpose: The processor handles its own business, and forwards it to other processors if it cannot handle it. Implementation
    : Abstract processor, holds its own reference processor as the upper level and processing request method, and then implements the abstraction, in the processing request method If it exceeds the scope of its own ability, it will be forwarded to the superior for processing
  20. Intermediary mode
    Purpose: Two classes that do not know each other, to get through a function, need the help of an intermediary to introduce and
    implement: abstract the behavior of two objects, abstract the intermediary, this intermediary holds the references of these two objects that do not know each other, in The intermediary exchanges messages with each other, and only the intermediary holds
  21. Flyweight mode
    Purpose: Frequent use of a shared item, which ensures high efficiency, can be considered for flyweight
    implementation: the factory maintains shared items and creates entity classes for user entry. When users frequently use entity classes, entities can be abstracted class, the factory holds entity classes and common data, and creates entity classes for users to use
  22. Interpreter mode
    Purpose: A requirement, different interpreters, to interpret information
    Realization: abstract interpreter, holding the entity class to be interpreted, concrete implementation of the interpreter, so that the same entity class encounters different interpreters. Same
  23. Visitor mode
    Purpose: A group of entity classes, presenting different responses to different visitors
    Realization: Abstract element class, this element class holds the visitor, abstract visitor class, the visitor encounters this element to produce different characteristics, here The two interworking functions are handed over to the manager, who collects elements and distributes them to different visitors
  24. Prototype mode
    Purpose: Clone itself
    Implementation: There is a copy method in the abstract prototype class, rewriting this method can initialize a new class

This question:

  • Encapsulate a request as an object so that the client can be parameterized with different requests; queue requests or record request logs, and support undoable operations. At this time, the command mode is used.
  • Among them, the declaration interface should be the highest level.
  • The command pattern is a behavioral object pattern.

48, 49. It is assumed that the context-free grammar describing simple arithmetic expressions is as follows, where id represents a single letter:

E→E+T|T
T→F*T|F
F→id

The syntax tree corresponding to the expression a+b c d described by this grammar is ( ), and the finite automaton (DFA) shown in the figure below is ( ).
insert image description here
1)
A, insert image description here
B, insert image description here
C, insert image description here
D, no

2)
A. Deterministic finite automaton, it can recognize the ending with bab
B. Deterministic finite automaton, it can’t recognize the ending with bab
C. Non-deterministic finite automaton, it can recognize the ending with bab
D. Non-deterministic finite automata, which cannot recognize endings in bab

Reference answer: AD
answer analysis: The process of
using derivation to construct a statement a+b c d is as follows:
insert image description here
the syntax tree after finishing is structured as follows:
insert image description here

  • Choose option A for the first time.
  • According to the judgment of the finite automata in the second space, starting from the initial state, the received character a may remain in the original state, or may transfer to the next state, which is uncertain, so it is an uncertain finite automaton. Secondly, the automaton recognizes that the third character from the bottom is only a, so it cannot recognize the character string ending in bab, and the second blank selects the D option.

50. The meanings of the functions foo and hoo are as follows. The two parameters of the function call hoo(a,x) are passed by reference (call by reference) and value (call by value) respectively, then the function call foo(5 ) The output result is ( ).
insert image description here
A.2,
5 B.2, 15
C.13, 5
D.13, 15

Reference answer: C
answer analysis:

  • Value transfer is to transfer the value of the variable, and will not change the value of the variable outside the method;
  • Passing by reference is to pass the address of the object, which will change the value of the object itself;

According to the information given by the question stem, foo(5), in this function, the initial situation x=5, a=2.
Call the hoo(a,x) function, at this time a=2 is passed to x in the hoo function, and because it is a reference method, the modification of x in the hoo function will affect the value of the original a (note the difference, the hoo function’s x and x of the foo function are local variables that are not used). At the same time, x=5 is passed to y in the hoo function, and it is a value call method. At this time, the modification of y in the hoo function will not affect the original value of x.
Then analyze the hoo() function, the initial value of x is 2, and the initial value of y is 5. Execute y=y+10=15, and execute x=yx=15-2=13. At this time, the value of x will be returned to a of the original foo function, that is, a=x=13.
Return to the foo function for analysis, and the output values ​​of a and x are the modified 13 and the original value 5, respectively.
Choose option C for this question.

Guess you like

Origin blog.csdn.net/johnWcheung/article/details/127538674