Final Exam Part 2 Flashcards
What is ‘Analysis’ in software engineering?
“Do the right thing”
+ Focus on the understanding of the problem (What?)
+ Requirements analysis
+ Domain analysis
What is ‘Design’ in software engineering?
"Do right, the thing" Focus on the understanding of the solution (How?) \+ Architecture \+ Structure \+ Closer to the actual code \+ Classes’ operations and attributes \+ Objects life cycle
Why does the principle of encapsulation promote good design?
Be able to give an example.
Encapsulation is a mechanism used to hide the data, internal structure, and implementation details of an element, such as an object or subsystem.
Example: Private variables by encapsulation require programmers to use function calls that manipulate, and access data the way they were intended.
Why does the principle of low coupling promote good design?
Be able to give an example.
Coupling is a measure of how strongly an element is connected to, is aware of, or depends on other elements. Principle of low coupling promotes good design by abstracting larger ideas into smaller functions. This creates less dependencies for the system as a whole, allowing easier maintenance.
Example: In a Car class, the Engine class would have a very specific role and only reference other classes when necessary and using private variables.
Why does the principle of high cohesion promote good design?
Be able to give an example.
Cohesion measures the degree of connectivity between elements of the same module, class, or object. Each class must execute a very specific set of closely related actions.
Example: class Foo { private SomeObject bar = new SomeObject();
public void FirstMethod() {
bar.FirstCall();
}
public void SecondMethod() {
bar.SecondCall();
}
public void ThirdMethod() {
bar.ThirdCall();
}
}
Explain how polymorphism can help to promote good design.
Be able to give an example.
Polymorphism is the provision of a single interface to entities of different types.
Example: A 'VolkswagenBeetle' class and 'SportsCar' class both have a public start() method. Both classes inherit attributes from the 'Car' class. A aggregate 'Driver' class can call the start() without knowing which subclass he is talking to.
Give an example of a situation in which you would use the Strategy design pattern. Be able to draw a class diagram.
The Strategy design enables a behavior to be selected at runtime.
This is useful when we have different possible instantiations of an object to consider.
For example a system in a restaurant might have two ways to bill customers.
If it is during happy hour, we create the ‘Consumer’ class object differently than if it was not. The consumer object depends on a ‘BillingStrategy’ interface.
The ‘NormalStategy’ and ‘HappyHourStrategy’ classes inherit from the interface a getPriceToPay() method. So depending on which class has been instantiated, the getPriceToPay() will act accordingly.
Give an example of a situation in which you would use the Template design pattern. Be able to draw a class diagram.
One or more algorithm steps can be overridden by subclasses to enable differing behaviors while ensuring that the overarching algorithm is still followed.
For example, say we have a ‘CrossCompiler’. This class has different functions depending on if it is for Iphone or Android. The method crossCompile() has collectSource() and compileToTarget(), each does the overarching algorithm. Also in the main class there are abstracted “template” methods, that are overwritten by the methods in the IphoneCompiler class and the AndroidCompiler class.
Upon creating an IphoneCompiler object, the methods in said subclass are run when using the method crossCompile() because they extend the CrossCompiler class.
Give an example of a situation in which you would use the Command design pattern. Be able to draw a class diagram.
An object is used to encapsulate all information needed to perform an action (method name, the object that owns the method and values for the parameters).
Command Pattern is useful when:
+A history of requests is needed
+You need callback functionality
+Requests need to be handled at variant times or in variant orders
+The invoker should be decoupled from the object handling the invocation
(You’ll also find Command useful for undo operations, wizards, progress bars, and other transactional behavior)
Example (Undo):
+ The Receiver object is an aggregate of concrete commands. It knows how to perform the actions - doAction() & undoAction().
+ The Command interface defines methods for operations. (With the addition of two methods: store() and load(), we could log all of our actions.)
+ The ConcreteCommand (which contains a receiver object) extends the Command interface, implementing the execute() method by invoking the corresponding operations on the Receiver object. It defines a link between the Receiver and the command action.
+ The Invoker asks the Command interface to carry out the request.
Give an example of a situation in which you would use the Composite design pattern. Be able to draw a class diagram.
Composite Pattern is useful when a group of objects is to be treated in the same way as a single instance of an object.
Example:
We might have a component class ‘Employee’, a primitive class ‘Worker’ and a composite class ‘Supervisor’. A supervisor is a composition of a worker and an employee, whereas the worker is only an employee. We don’t want to treat a Supervisor object exactly like a Worker object so we separate them into subclasses of the component class.
Give an example of a situation in which you would use the Singleton design pattern. Be able to draw a class diagram.
Restricts the instantiation of a class to one object. The singleton class must provide a global access point to get the instance of the class.
Commonly used for logging, driver objects, file systems, caching and thread pools.
“Logging is a specific example of an “acceptable” application because it doesn’t affect the execution of your code. Disable logging, code execution remains the same. Enable it, same same. Misko puts it in the following way in Root Cause of Singletons, ‘The information here flows one way: From your application into the logger. Even though loggers are global state, since no information flows from loggers into your application, loggers are acceptable.’
Alex Miller, in “Patterns I Hate”, talks of service locators and client side UI’s also being possibly “acceptable” choices.”
Give an example of a situation in which you would use the Bridge design pattern. Be able to draw a class diagram.
Bridge design patterns decouple an abstraction from its implementation so that the two can vary independently. You may have a set of methods that you contemplate implementing in two or more completely different ways.
“…it is a way of encapsulating alternate versions of a whole range of methods rather than encapsulating alternate versions of just one method.”
Example: A remote control with multiple appliances.
A ‘Switch’ object is an aggregation of an ‘Appliance’ interface (containing an Appliance object).
Inheriting from this interface is two appliances, ‘TV’ and ‘VaccumCleaner’. Each has a different implementation of the function ‘run()’.
Inheriting from the ‘Switch’ class, ‘RemoteControl’ has a function ‘turnOn()’ that calls the run() function in the interface on the instantiated object. Depending on the instantiated type of the appliance object, run() will operate differently.
What are the steps/commands to get code from a Git repository?
You typically obtain a Git repository in one of two ways:
+ You can take a local directory that is currently not under version control, and turn it into a Git repository
$ git init
$ git add *.c
$ git add LICENSE
$ git commit -m ‘initial project version’
OR
+ You can clone an existing Git repository from elsewhere
$ git clone
What are the steps/commands to change code from a Git repository?
Then we optionally branch (to assure the master branch only contains finished/approved work) and make changes:
$ git branch - creates new branch
$ git checkout - moves HEAD pointer to desired branch
After the changes, we first add files in the new local repository and commit our changes to the local branch
$ git add .
$ git commit -m “”
What are the steps/commands to push code a remote Git repository?
Add the URL for the remote repository where the local repository will be pushed:
$ git remote add origin remote (sets the new remote)
$ git remote -v (verifies the new remote URL)
Then we push our local changes -
$ git push origin master
What are the steps/commands to upload via a Pull-Request into a Git repository?
To upload via a pull request, go to the repository page on github.
Click on “Pull Request” button in the repo header
Enter a title / description / comments if desired and submit.
*Bonus:
What are the steps/commands to merge a Pull-Request into the root Git repository.
Merging a pull request:
Checkout the branch you’re merging to in the target repo
$ git checkout master
Pull the development branch from the fork repo where the pull request development was done -
$ git pull
Merge the development branch -
$ git merge
Push master with the new feature merged into it -
$ git push origin master
Delete the development branch when done -
$ git branch -d
What is a build tool?
Build tools are programs that automate the creation of executable applications from source code.
Building incorporates compiling, linking and packaging the code into a usable or executable form.
Apache Maven is an example of a build tool.
What is ‘continuous integration’?
+ Members of a team integrate their work frequently
+ Usually each person integrates at least daily – leading to multiple integrations per day.
+ Each integration is verified by an automated build (including testing) to detect integration errors as quickly as possible.
What is ‘continuous deployment’?
+ Teams produce software in short cycles
+ Ensures that the software can be reliably released at any time
What is clean code?
“Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer’s intent but rather is full of crisp [clearly defined] abstractions and straightforward lines of control.” - Grady Booch
Clean code is a perspective, but to create such code, one should focus on clarity and readability. Meaningful names, small functions, DRY, KISS and spacing helps to achieve this.
What is refactoring?
Prepare an example of one of the refactorings proposed by Martin Fowler in his book “Refactoring: Improving the Design of Existing Code.”
Refactoring is the process of restructuring existing source code without changing its external behavior.
Improving the design of the code after it has been written improves non-functional properties.
Example:
Encapsulate Field -
“There is a public field.
Make it private and provide accessors.”
Why are coding conventions important?
Coding conventions are a set of guidelines for writing code for a specific programming language or technology. They improve readability and, consequently, maintainability.
Remember that ~75% of the cost of a project goes to maintenance and that, very often, the code is edited by others than the original author.
What is the Hungarian notation?
Hungarian notation, is an identifier naming convention in computer programming, in which the name of a variable or function indicates its intention or kind, and in some dialects its type.
Discuss the practice of separation of concerns. Give an example
Separation of concerns, is a design principle for separating a computer program into distinct sections, such that each section addresses a separate concern. (Link)
Example: A class ‘Fruit’, should not have anything to do with a class called ‘Business’, unless this business is heavily reliant on the ‘Fruit’ class for some reason. In which case the ‘Fruit’ class is probably not well-enough defined.
What is a fluent API (fluent interface)? Give an example.
A method for designing object oriented APIs based extensively on method chaining with the goal of making the readability of the source code close to that of ordinary written prose, essentially creating a domain-specific language within the interface.
Example:
mock.expects(once()).method(“m”).with( or(stringContains(“hello”),
stringContains(“howdy”)) );
What is a code smell? Give 3 examples
Code smell, also known as bad smell, refers to any symptom in the source code of a program that possibly indicates a deeper problem.
Examples:
+ Duplicated Code
+ Feature Envy, a class that uses methods of another class excessively
+ One Large class, a class that does too much
*Bonus:
What is a CFG?
CFG = control flow graph
+ The nodes of the graph correspond to indivisible groups of commands of a program.
+ A directed edge connects two nodes if the second command might be executed immediately after the first command.
How is the metric Cyclomatic Complexity (McCabe) calculated?
Computed using the CFG of the program.
“The number of linearly independent paths through the flow graph from an entry to an exit.”
*Bonus
What is LCOM1?
LCOM1 stands for Lack of Cohesion Among Methods of a Class, which measures the extent of intersections of individual method parameter type lists with the parameter type list of all methods in the class.
How is the metric LCOM1 calculated?
Take each pair of methods in the class.
If they access disjoint sets of instance variables, increase P by one.
If they share at least one variable access, increase Q by one.
LCOM1 = P - Q // if P > Q LCOM1 = 0 //otherwise
‘LCOM1 = 0’ indicates a cohesive class.
‘LCOM1 > 0’ indicates that the class needs or can be split into two or more classes, since its variables belong in disjoint sets.
Classes with a high LCOM1 have been found to be fault-prone.
What is ‘Verification’ in software engineering?
Verification – “Are we building right, the product?”
+ The evaluation of whether or not a product complies with the requirements
+ Tests
What is ‘Validation’ in software engineering?
Validation – “Are we building the right product?”
+ The assurance that a product meets the needs of the customer and other stakeholders.
+ User evaluation
What is ‘White Box’ testing?
+ You know the code
+ Logical paths throughout the code are tested (conditions, loops, calls, etc.)
Example:
White Box testing is like the work of a mechanic who examines the engine to see why the car is not moving.
What is ‘Black Box’ testing?
+ You know the functionality
+ Testing the functionality of a system by observing its external behavior
Example:
A tester, without knowledge of the internal structures of a website, tests the web pages by using a browser; providing inputs (clicks, keystrokes) and verifying the outputs against the expected outcome.
What is a ‘Unit’ test?
+ A test of an individual unit
+ Written and executed by the programmer
+ Generally white box
What is an ‘Integration’ test?
+ Units are combined
+ The interactions among units are tested
+ Mix of black and white box
What is an ‘Acceptance’ test?
+ Test whether the system meets the acceptance criteria
+ Generally done from the GUI
+ Black box
What is regression testing?
Regression testing is a type of software testing which ensures that previously developed and tested software still performs the same way after it is changed or interfaced with other software.
Why and how are mock objects used for unit testing?
Mock objects mimic the behavior of real object in a controlled way. Mock objects are created to test the functionality of other objects like a crash test dummy is used in car crash testing to mimic a real human.
Useful for isolating the test of one object from another or when we have objects that are difficult to create, to reproduce, that are slow, etc.
A mock object can be created with a subclass of the original class. This class has other data injected into it so you avoid testing the injected parts and solely focus on testing the rest of the code.
What is TDD? How may it improve class design?
Test Driven Development is a software development method where the developers write the tests first (based on user requirements) and then write code to pass those tests. TDD follows this cycle:
+ Write a test that fails
+ See it fail
+ Make the test pass in the simplest possible way
+ See it pass
+ Refactor to remove duplication of data and code and repeat
Explain two techniques for software validation (form of user evaluation).
Heuristic evaluation - assess tool for usability.
Cognitive walkthrough - simulate actions needed to complete task.
What are the benefits and the drawbacks of the waterfall model?
Benefits: • Document-oriented • Specialists for each phase • Quality group approving each phase • Facilitates management Drawbacks: • Errors are perceived too late • Team impatience to start coding and client impatience to receive software • Fights in contract renegotiations • Moving target
Explain each of the 4 phases of the ‘unified process’.
Inception - The primary objective is to scope the system adequately as a basis for validating initial costing and budgets.
Elaboration - The primary objective is to mitigate the key risk items identified by analysis up to the end of this phase.
Construction - The primary objective is to build the software system.
Transition - The primary objective is to ‘transit’ the system from development into production, making it available to and understood by the end user.
Explain the goal of 3 workflows of the unified process.
Pick 3:
Business Modeling - The goal is to understand the business of the organization (usually only the part relevant to the system).
Requirements - The goal is to raise, document, and create an agreement among those involved about what will be built.
Analysis and design - The goal is to analyze the requirements and design a solution to be implemented.
Implementation - The goal is to turn design into executable code.
Tests - The goal is to perform checks to ensure quality.
Deployment - The goal is to put the system into operation.
Configuration and change management - The goal is to manage changes in project artifacts.
Project management - The goal is to coordinate the project.
Environment - The goal is to ensure that processes, guides and tools are available to the team.
What is CMMI and what is it used for?
Capability Maturity Model Integration (CMMI) - a process level improvement training and appraisal program.
CMMI describes both software and system engineering in order to:
+ Produce quality products or services
+ Create value for the stockholders
+ Enhance customer satisfaction
+ Increase market share
+ Gain an industry-wide recognition for excellence
List 4 practices adopted in Extreme Programming.
Fine-scale feedback:
+ Pair programming
+ Planning game
+ Test-driven development
Continuous process:
+ Continuous integration
+ Refactoring or design improvement
+ Small releases
Shared understanding: \+ Coding standards \+ Collective code ownership \+ Simple design \+ System metaphor
Programmer welfare:
+ Sustainable pace
Coding: \+ The customer is always available \+ Code the unit test first \+ Only one pair integrates code at a time \+ Leave optimization until last \+ No overtime
Testing:
+ All code must have unit tests
+ All code must pass all unit tests before it can be released.
+ When a bug is found, tests are created before the bug is addressed (a bug is not an error in logic, it is a test that was not written)
+ Acceptance tests are run often and the results are published
What is the ‘Scrum’ method?
A framework for implementing agile (like kanban).
The Scrum method calls for four ceremonies that bring structure to each ‘sprint’ (fixed-length product iterations):
Sprint planning - A team planning meeting that determines what to complete in the coming sprint.
Daily stand-up (daily scrum) - a 15-minute mini-meeting for the software team to sync.
Sprint demo - A sharing meeting where the team shows what they have shipped in that sprint.
Sprint retrospective - A review of what did and did not go well. (Includes actions to make the next sprint better)
*Bonus:
What comprises a Scrum team?
A product owner - focus is on ensuring the development team delivers the most value to the business
A scrum master - Coach of the whole team. Deeply understands the work being done by the team and can help the team optimize their delivery flow.
As the facilitator-in-chief, they schedule the needed resources (both human and logistical) for sprint planning, stand-up, sprint review, and the sprint retrospective.
Scrum masters also look to resolve impediments and distractions for the development team, insulating them from external disruptions whenever possible.
Scrum team - usually 5-7 team members. Each member has differing skill sets who can crosstrain each other to avoid a bottleneck programmer.