Lesson 3 Flashcards
What does “SOLID” stand for in OOP?
Single Responsibility Principle.
Open/Closed Principle.
Liskov Substitution Principle.
Interface Segregation Principle.
Dependency Inversion Principle.
What is the Single Responsibility Principle (SRP)?
A class should have only one reason to change, meaning it should have only one responsibility or job.
How can you apply the Single Responsibility Principle (SRP) in Java?
By creating classes that have a clear and single responsibility. If a class has multiple responsibilities, it should be split into smaller, more focused classes.
What is the Open/Closed Principle (OCP)?
Software entities should be open for extension but closed for modification, allowing new functionality to be added without modifying existing code.
What does the Liskov Substitution Principle (LSP) state?
Subtypes should be substitutable for their base types without affecting the correctness of the program.
How can you apply the Open/Closed Principle (OCP) in Java?
By designing classes that are open for extension but closed for modification, using interfaces, abstract classes, and polymorphism.
How can the Liskov Substitution Principle (LSP) be applied in Java?
By creating subclasses that can be used in place of their superclass, without altering the expected behavior.
What is the Interface Segregation Principle (ISP)?
Clients should not be forced to depend on interfaces they do not use. Interfaces should be small and focused.
How can you implement the Interface Segregation Principle (ISP) in Java?
By creating small and focused interfaces that clients only depend on as needed, avoiding large, general-purpose interfaces.
What is the Dependency Inversion Principle (DIP)?
High-level modules should not depend on low-level modules; both should depend on abstractions.
Give a real-world example of the Single Responsibility Principle (SRP).
In a web application, a User class handles user-specific operations, while an EmailService class handles sending emails, ensuring separation of concerns.
How can you apply the Dependency Inversion Principle (DIP) in Java?
By using interfaces or abstract classes to define behavior and using dependency injection to provide specific implementations.
Provide an example of applying the Open/Closed Principle (OCP) in a payment system.
Defining a PaymentProcessor interface and having multiple classes, such as CreditCardProcessor and PayPalProcessor, implement it to add new payment methods without modifying existing code.
Describe a violation of the Liskov Substitution Principle (LSP).
A Penguin class inherits from Bird but changes the behavior of the fly() method, which is not appropriate since penguins cannot fly.
How can the Interface Segregation Principle (ISP) be applied to a messaging system?
Instead of a single IMessage interface with multiple methods, create smaller interfaces like ISender and IReceiver for specific functionality.
How does the Dependency Inversion Principle (DIP) benefit an e-commerce application?
It allows the OrderProcessor class to depend on an IPaymentGateway interface, making it easy to switch between different payment providers.
What is Maven?
Maven is a build automation and dependency management tool used primarily for Java-based projects.
What file does Maven use to configure a project?
pom.xml (Project Object Model)
What are the three main coordinates that uniquely identify a Maven project?
<groupId>, <artifactId>, and <version>
</version></artifactId></groupId>
What is the purpose of the <dependencies> tag in pom.xml?</dependencies>
To specify the libraries or dependencies required by the project.
How do you check if Maven is installed using the command line?
mvn –version
What is a Maven “lifecycle”?
A sequence of phases that define the stages in the build process, such as Validate, Compile, Test, Package, etc.
What Maven command is used to compile a project?
mvn compile
What does the mvn package command do?
It packages the compiled code into a JAR or WAR file.
What tool does Maven integrate with for code coverage analysis?
JaCoCo (Java Code Coverage)
What does a red diamond in a JaCoCo report indicate?
No branches have been exercised during the test phase.
What are the three main code coverage metrics provided by JaCoCo?
Line coverage, branch coverage, and cyclomatic complexity.
What is the purpose of the <plugins> section in pom.xml?</plugins>
To list plugins that extend Maven’s functionality, such as JaCoCo for code coverage.
What is the role of the <executions> tag in a Maven plugin configuration?</executions>
To define specific goals to be executed during particular phases of the build lifecycle.
How do you run a specific Maven goal?
Use the syntax mvn plugin:goal (e.g., mvn dependency:copy-dependencies)
What does the mvn clean verify command do?
Cleans the project and runs all verification tasks, including tests and coverage checks.
Why is 100% code coverage not always indicative of effective testing?
It only shows how much code is executed, not how well the code is tested or if all edge cases are covered.
What does <scope> define in a dependency within pom.xml?</scope>
The visibility and usage of the dependency (e.g., compile, runtime, test).
What command can generate a JaCoCo report after tests have run?
mvn jacoco:report
What is the Maven Build Lifecycle?
It is a predefined sequence of phases that a Maven build goes through, representing steps like compiling, packaging, and deploying the code.
What environment variable needs to be set when installing Maven on Windows?
PATH variable to include Maven’s bin directory.
List the phases of the Maven Build Lifecycle in order.
- Validate
- Compile
- Test
- Package
- Verify
- Install
- Deploy
What is the purpose of the “compile” phase in Maven?
To compile the source code of the project
What happens during the “validate” phase of the Maven Build Lifecycle?
Maven checks that the project is correct and that all necessary information is available.