Final Exam Part 2 Flashcards
(49 cards)
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.