Unit 2 Flashcards

1
Q

What does the acronym SOLID stand for in software design?

A

Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion

SOLID principles aim to make software more understandable, maintainable, and extensible.

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

Who presented the SOLID design principles?

A

Robert Martin

These principles were introduced in ‘Design Principles and Design Patterns’ (2000).

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

What is the first principle of SOLID design?

A

Single Responsibility Principle

A module should be responsible to one, and only one, actor.

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

Define Single Responsibility Principle.

A

A class should have only one reason to change.

Responsibility refers to the reason for change related to the role a class performs.

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

What is an anti-pattern of the Single Responsibility Principle?

A

The ‘God’ class

It knows everything, does everything, and changes for everything, making it a maintenance nightmare.

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

What does the Open/Closed Principle state?

A

Software entities should be open for extension, but closed for modification.

This means existing behaviors do not change, while new features can be added.

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

What is the importance of the Liskov Substitution Principle?

A

Objects in a program must be replaceable by subtypes without altering correctness.

Inheritance implies substitutability.

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

What does the Interface Segregation Principle emphasize?

A

Clients should not depend on interfaces they do not use.

It promotes organizing interfaces around tasks and separating them for different functionalities.

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

What is the Dependency Inversion Principle?

A

High-level modules should not import anything from low-level modules. Both should depend on abstractions.

This principle aims to reduce dependency and improve flexibility.

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

Fill in the blank: A module should be responsible to one, and only one, _______.

A

actor

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

What problem does the ‘God’ class exemplify?

A

Maintenance nightmare due to excessive responsibilities.

Changes in specification require updating the entire class.

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

What should be the relationship between high-level and low-level modules according to the Dependency Inversion Principle?

A

Both should depend on abstractions.

This avoids brittleness and promotes reusability.

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

What does the term ‘clopen’ refer to in the context of the Open/Closed Principle?

A

A combination of open and closed.

It describes the need to separate what is open for extension and what is closed for modification.

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

What is a major consequence of violating the Liskov Substitution Principle?

A

Subtypes may violate the promises made by their supertype.

This can lead to unexpected behavior in programs.

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

Give an example of a design flaw that arose in Python 2.5.

A

Fundamental design flaws that required breaking backwards compatibility to fix.

This led to the release of Python 3.0.

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

What does the Interface Segregation Principle suggest about the design of interfaces?

A

Organize interfaces around tasks and separate them for different functionalities.

This approach prevents clients from depending on unused methods.

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

What is a key benefit of having thin interfaces?

A

Easier to extend and maintain.

They lead to more focused behaviors that are easier to test.

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

True or False: The Dependency Inversion Principle states that abstractions should depend on details.

A

False

It states that details should depend on abstractions.

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

What does it mean for a class to have a single responsibility?

A

It should only have one reason to change.

This relates to the class’s role within the software.

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

What is the purpose of source code documentation?

A

To explain the functionality and usage of the code.

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

Define self-documenting code.

A

Code that explains itself through its structure and naming conventions.

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

What is Javadoc documentation?

A

A tool that generates API documentation in HTML format from Java source code.

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

Why is programming style important?

A

It enhances readability and maintainability of code.

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

Fill in the blank: ‘You read code ______ as often as you write it.’

A

10x

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What does consistent formatting in coding help with?
It allows for quick comprehension of code at a high level.
26
What are key features of self-commenting code?
* Descriptive naming conventions * Clear structure * Meaningful function parameters * Expressive variable names
27
True or False: Inconsistent documentation can be worse than no documentation at all.
True
28
What should end user documentation explain?
* What the file/class/function does * The public interface provided * Behavior of each method * Required inputs and outputs
29
What are the main responsibilities of writing documentation?
* Update comments within the source code * Update documentation for users
30
What is a documentation generator?
A tool that produces documentation from code and comments.
31
What is the command to generate Javadoc from the command line?
javadoc
32
What is the purpose of Javadoc comments?
To provide qualitative details about the code in a structured format.
33
What is the format for starting a Javadoc comment?
/**
34
What does the @param tag in Javadoc indicate?
It describes a method parameter and its meaning.
35
What does the @throws tag in Javadoc indicate?
It specifies the exception that a method may throw.
36
What does the @deprecated tag indicate in Javadoc?
It marks a feature that is available but will be removed in the future.
37
What is the result of using the @see tag in Javadoc?
It creates a hyperlink to another method or class in the documentation.
38
What should you do when you update code?
Update the comments and documentation to reflect the changes.
39
What are the key components of a method header comment in Javadoc?
* Description of the method * Assumptions about inputs/outputs * Tags for parameters and return values
40
What does the term 'programming style' encompass?
* Consistent coding style * Organization of code * Naming conventions
41
What are some factors that influence the choice of a coding style?
* Company style policy * Language used * Personal preferences
42
What is the significance of the quote by Martin Fowler?
It emphasizes the importance of writing understandable code for humans.
43
What is unit testing?
Software testing focused on a single unit of software.
44
What is a unit in unit testing?
A meaningful, complete piece of code that performs a specific, concrete, well-defined behavior.
45
What does 'works' mean in the context of code?
Runs without crashing, seems to work properly, or meets specification.
46
What are some large software projects mentioned?
* COSC 1020 project: ~200 lines * Unix 1.0: 4501 lines * Space Shuttle control code: ~400,000 lines * Jurassic Park: 2,000,000 lines * Google Chrome: 6.7M lines * macOS 10.4: 86M lines
47
What is one notable failure related to software systems?
Ariane 5 Rocket exploded 37 seconds after takeoff due to a horizontal bias controller failure.
48
What are the advantages of unit tests?
* Can be automated * Run tests early and often * Locate bugs early * Cheaper in time and money * Allow refactoring implementations * Simplify integration testing
49
What are the disadvantages of unit tests?
* Test count can be large * Cannot test exhaustively * Cannot replace all kinds of tests
50
What are the three steps in designing a unit test?
* Arrange * Act * Assert
51
What does the 'Arrange' step involve?
Setting up the testing conditions and the unit under test.
52
What is the purpose of mock objects?
They provide the same promise as a real object and can be configured to 'fail on command' to test error-handling.
53
What is a unit test supposed to consider?
A single behavior, avoiding use cases with multiple steps.
54
What does SOLID stand for in programming?
Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion.
55
What is JUnit?
A Java framework for unit testing.
56
What are the two major versions of JUnit in widespread use?
* JUnit 5 * JUnit 4
57
What does the @Test annotation do in JUnit?
Identifies a method as a unit test.
58
What is the purpose of the @BeforeEach annotation?
To define a setup method that runs before each test method.
59
What does the @ParameterizedTest annotation allow?
To run the same test logic with different inputs.
60
What is the function of assertions in JUnit?
To determine test outcomes and communicate results.
61
What does the method assertEquals do?
Tests value equality and reports expected and actual values on failure.
62
What is the purpose of the assertNull method?
To assert that an object is null.
63
What is a common feature of most assertion methods in JUnit?
They can take an optional String parameter that provides a message if the assertion fails.
64
What is the function of the @Disabled annotation?
To turn off a test method so the test runner skips it.
65
What is the default test lifecycle in JUnit?
Instantiate the test class, run @BeforeEach methods, run a single @Test, and then run @AfterEach methods.
66
What is the purpose of assertEquals?
Asserts abs(exp – act) < tol ## Footnote Used to verify that two values are equal within a specified tolerance.
67
What does assertSame do?
Asserts reference equality ## Footnote It checks if two references point to the same object.
68
What is the function of assertNull?
Asserts that the object is null ## Footnote Used to verify that a variable does not reference any object.
69
What does assertThrows do?
Asserts that an exception is thrown ## Footnote It is used to test that a specific exception occurs during execution.
70
What is a lambda expression?
An anonymous function ## Footnote Allows passing behavior as a function parameter.
71
What does assertTimeout check?
Tests that behaviors finish within required time limits ## Footnote It ensures that the execution time of a block of code does not exceed a specified duration.
72
What is the purpose of assertAll?
Asserts several executables in parallel ## Footnote It reports which child executables failed and their failures.
73
What are JUnit assumptions?
Static member methods of org.junit.jupiter.api.Assumptions ## Footnote They succeed silently and fail by skipping the test.
74
What are the two primary assumptions in JUnit?
* assumeTrue(bool [, msg]) * assumeFalse(bool [, msg]) ## Footnote Used for conditional execution of tests.
75
Why is it important to combine test suites?
Protect against regressions ## Footnote It ensures that new changes do not break existing functionality.
76
What is the annotation used to combine test suites in JUnit?
@RunWith(JUnitPlatform.class) ## Footnote It specifies which test runner to use for the suite.
77
How do you include all test suites in a package?
@SelectPackages("org.rbev.tests") ## Footnote This annotation includes all test classes within the specified package.
78
What does the @ExcludePackages annotation do?
Explicitly excludes some subpackages ## Footnote It prevents certain packages from being included in test execution.
79
What is the purpose of the @IncludeTags annotation?
Selecting tags for test methods ## Footnote It allows only tests with specific tags to be executed.
80
What does assertNotNull assert?
Asserts that the object is not null ## Footnote Used to verify that a variable does reference an object.
81
What is the significance of the lambda symbol in a lambda expression?
Indicates the beginning of the function body ## Footnote It is represented by '->' in the syntax.
82
What does assertTimeoutPreemptively do?
Runs the behavior, aborts early if time limit is reached ## Footnote It ensures that the test does not run longer than expected.
83
What is the purpose of arranging inputs and assumptions in unit tests?
To set up the conditions under which the tests will run ## Footnote Assumptions can include OS or library versions.
84
What is a key alternative to debugging?
Not having to debug.
85
How can you avoid debugging?
By making bugs less likely.
86
What is regression testing?
Run every unit test every time you make a change.
87
What indicates that a bug was introduced?
If any formerly-passing tests fail.
88
What should you create from every bug?
A test case.
89
How do you identify a bug?
By its input and output.
90
What is the purpose of a unit test?
To specifically test the behavior of a bug.
91
What does 'fail fast' mean?
Use static typing, final, and compiler annotations.
92
What should you let the compiler enforce?
What you mean to do.
93
What does 'fail loud' imply?
Turn runtime errors of intent into compiler errors.
94
What is a code assertion?
It expresses a programmer’s assumptions.
95
What happens when an assertion doesn’t hold?
The program won't work properly from that point onward.
96
What is an example of an assertion in Java?
JUnit assertions.
97
What should you do when an assertion is not true?
The test case results are not meaningful.
98
What is the purpose of documenting and enforcing assumptions?
To ensure the documentation requires certain conditions.
99
What is Java’s assert statement?
A built-in language construct for asserting conditions.
100
What does the assert statement syntax look like?
assert boolean_expression : description;
101
What happens if the boolean expression in an assert statement is true?
Continue silently.
102
What happens if the boolean expression in an assert statement is false?
Throw AssertionError and crash the program.
103
When should you assert in your code?
Wherever you assume.
104
What characteristics should asserts have?
They should be short and self-documenting.
105
What do assertions help with?
Detecting programming errors.
106
What is unusual about assert statements in Java?
They are NOP by default.
107
How do you enable assert statements during execution?
Use the run-time flag -ea.
108
What should expressions in assert statements be?
Side-effect free.
109
What could happen if an assertion is turned off?
The side-effect may not be performed.
110
What is the Waterfall method?
A linear and sequential software development process where progress flows downward and requires completing each step before moving on. ## Footnote Good for projects with fixed scope and known requirements.
111
What does Agile software development emphasize?
Tighter coupling between client and developer, more frequent communication and feedback, flexibility for evolving specifications, and faster turnaround to something working. ## Footnote Developed in the 1990s and formalized in the 2010 Manifesto for Agile Software Development.
112
Define Software Engineering.
The application of a systematic, disciplined, quantifiable approach to the development, operation, and maintenance of software. ## Footnote IEEE Standard 610-1990 defines it as applying engineering principles to software.
113
What is Extreme Programming?
A software development methodology that emphasizes good programming practices taken to an extreme level, including partner coding and continuous integration. ## Footnote Features frequent client interaction and test-driven development.
114
What is Test-Driven Development (TDD)?
A software development process where tests are written before the code that needs to pass the tests. ## Footnote It includes steps like writing a test, running all tests, and refactoring the solution.
115
What are UML diagrams used for?
To describe software design and development visually, capturing various aspects of the system. ## Footnote UML stands for Unified Modeling Language.
116
What are Sequence diagrams in UML?
Diagrams used to model interactions and messages between participants in a system. ## Footnote They include lifelines, messages, and executions.
117
What is the difference between a synchronous and asynchronous call in UML?
A synchronous call waits for a response, while an asynchronous call does not wait and continues other work. ## Footnote Synchronous calls are represented with a solid arrowhead, and asynchronous calls with an open arrowhead.
118
What does a Class diagram represent?
Classes involved in software, including attributes, behaviors, and access rules. ## Footnote It shows relationships between classes like interactions and ownership.
119
What is an Activity diagram used for?
To model stepwise actions or activities, highlighting sequential activities and decision-making. ## Footnote It appears similar to a flowchart.
120
Fill in the blank: The Waterfall method is good for projects with _______.
Fixed scope and known requirements.
121
True or False: Agile software development allows for flexibility in specifications.
True.
122
What are the two types of relationships shown in Class diagrams?
* Association * Aggregation and Composition * Generalization ## Footnote These relationships illustrate how classes interact within a system.
123
What do Decision nodes represent in Activity diagrams?
Branching execution points where one way in leads to multiple ways out based on conditions. ## Footnote They are typically depicted as diamonds.
124
What is the purpose of a Join node in Activity diagrams?
To bring concurrent flows back together at a synchronization point. ## Footnote All flows must reach the join node before continuing.
125
What is a Merge node in Activity diagrams?
A node that brings flows back together after decisions, allowing at most one input branch to be taken. ## Footnote It does not support concurrent execution.
126
What are the core elements of Class diagrams?
* Class type * Attributes * Operations ## Footnote Member visibility can be marked as public, protected, package, or private.