Version Control Using Git
Version Control Using Git
Version Control Using Git
using Git
Coding
• All the design and thinking get transformed to an
implementation.
• The main outcome is the code
• Software Engineer Vs Programmer
Need for Version Control
void drawPicture() {
drawCircle();
for (int i = 0; i < 10; i++) {
void drawPicture() {
drawTriangle();
drawCircle();
}
for (int i = 0; i < 100; i++)
} {
drawSquare();
}
}
void drawPicture() {
drawCircle();
for (int i = 0; i < 10; i++) {
drawTriangle();
}
}
Need for Version Control
Source:
https://geo-python-site.readthedocs.io/en/latest/lessons/L2/i
ntro-to-GitHub.html
Need for Version Control
cd /home/user/projects/sample_proj
git init
This will initialize git and a .git folder will get created inside the
project path
Setting up a new Repository: Config
Config is to get or set global properties for the repository
sample-proj
test.c
Git status
git status
States of a file
Untracked: When a new file is created it is untracked
git add
How to Commit?
• When a file is committed, it becomes a part of the local
repository.
• All the staged files get committed
git commit -m <commit message>
git status
Source: https://dev.to/sublimegeek/git-staging-area-explained-like-im-five-1anh
Viewing commit history
git log
test.c
add_integer.c
Modified test.c
C3
C2
C1
Undoing things
HEAD
C1 C2 C3
HEAD
C1 C2 C3
Undoing Things: go back to a previous
commit
git reset <commit id>
Reverts to the previous commit referred by the commit id
git log
git status
Undoing Things: Revert
HEAD
C1 C2 C3
HEAD
C1 C2 C3 Reset
HEAD
C1 C2 C3 C4 Revert
Undoing Things: Revert
git revert 413cef719a54ceb372892d3ae13b1aa61c562f91
Removing files
git rm <path>
• This removes the file or folder from the tracked file.
• This should be followed by a commit.
git rm test.c
More Insights into Commit
Commit Object
Name HEAD
Email
Commit message
Pointer
C1 C2 C3
Staging snapshot
Branching
Master Branch
HEAD
C1 C2 C3
Why Branching?
Branching helps to diverge from the main line of development
without disturbing the main line.
C1 C2 C3 C4
C4_b C5_b
Create a new branch
git branch <branch name>
git branch
git branch
Switch to a branch
git checkout <branch name>
git branch
Committing in a branch
Modified add_integer.c to add 3 integers instead of 2
git add add_integer.c
git commit -m "modified add_integer.c to add 3 integers"
git log
Committing to a branch: Visualization
C1 C2 C3
C4_b
Modifications
C1 C2 C3 C4 to test.c
C4_b
Add 3 integers
Git log: view all branches
git log --decorate --graph --all --oneline
Merging of branches
git merge <branch name>
HEAD
Modifications
C1 C2 C3 C4 to test.c
Add 3
C4 integers
_b
HEAD
C1 C2 C3 C4 C5
Add 3
integers
C4
_b Add 3
integers
Merging of branches
git checkout master
git merge test-branch
git log
Project Estimation
Project Planning → Project Estimation
● Resources
● Cost
● Time
Estimation of Resources
Estimation of Cost and Time (Effort)
● Decomposition Technique
These models are based on experience (historical data) which takes the form
where vi are independent parameters and d is one of the estimated values (eg.
effort, cost, project duration)
Decomposition: LOC Based Estimation
E-commerce website
Function Estimated LOC
Based on the average productivity (FP/pm) of the organization, cost and effort are
estimated.
values in person-months
Empirical Estimation Models
● Empirically derived formulas
● Predict effort as a function of LOC or FP
FP oriented models
Software Projects a b c d
Intermediate Model
Uses various other factors known as cost drivers. 15 cost drivers.
Eg. Size of the application database, complexity of the product, Programming language
experience
Detailed Model
● Unrealistic deadline
● Changing customer requirements
● Underestimation of effort and resources
● Risks which were not considered in the beginning
● Technical difficulties
● Human difficulties
● Miscommunication among staff
● Project management not recognising that the project is falling behind
Project Scheduling
● Was first created by the US Navy in 1950s to guide the Polaris nuclear
submarine project.
PERT
Nodes: Tasks
Arrows: dependencies
Source: https://monday.com/blog/project-management/pert/
PERT: Critical Path
● The tasks in this path are critical because delay in the execution of these tasks
will delay the whole project.
PERT Analysis
Step 1
For PERT analysis 3 time estimates are obtained
● Optimistic Time (O): Minimum possible time required to complete a task.
● Pessimistic Time (P): Maximum possible time required to complete a task.
● Most Likely Time (M): Best estimate of time required to complete a task.
PERT Analysis
Step 2
● Is a timeline chart
● First Gantt chart was made in 1890s by a Polish engineer Karol Adamiecki who
ran a steel works.
● After around 15 years, an American engineer Henry Gantt made his own
version of the chart.
Gantt Chart
Source: https://www.tacticalprojectmanager.com/earned-value-analysis/
Earned Value Chart: Example
Earned Value Chart: Example
Source: https://dreamcivil.com/earned-value-analysis/
Earned Value Metrics
Actual Cost (AC): The amount of costs effectively incurred up until now.
Earned Value (EV): Earned Value (EV) is the value of the work that has been
effectively completed
Example: Imagine a project consisting of 3 activities. You have completed activities 1
and 2 so far. The planned cost for activity 1 is $2,500 and $1,000 for activity 2. You
have spent $3,700 up to now. Then the Earned Value for the project at the current
point in time is $2,500 + $1,000 = $3,500
SV (Schedule Variance): How far ahead or behind is the project? The SV is calculated
as the difference between Earned Value and Planned Value, meaning SV = EV – PV.
SPI (Schedule Performance Index): How far ahead or behind schedule is the project,
expressed as a ratio of the overall project duration. SPI = EV / PV.
An SPI of less than 1 indicates your project is behind schedule, whereas a value > 1
means you are ahead of schedule.
CPI (Cost Performance Index): How far above or below the budgeted cost the
project is in comparison with the total approved project budget. CPI = EV / AC
CV (Cost Variance): Looking at the project right now, how far under or over budget
is it? The Cost Variance is calculated as CV = EV – AC.
Design Patterns
Design Patterns
Someone has already solved your problems !!
Duck Simulator Example (source: Head First Design Patterns, 2nd ed.)
Rubber duck
Design 2: Solution to Design 1 Flaw
Duck
quack()
swim()
display()
fly()
RubberDuck
display() {
//looks like a redhead
MallardDuck }
RedHeadDuck fly() {
//override to do
display() { nothing
//looks like a mallard display() { }
} //looks like a redhead quack() {
} //overridden to
squeak
}
Design 2: Flaw
● Overriding solution is not a cleaner way
● There will be issues with maintenance when there are modifications
in the future.
● Whenever a new Duck subclass is added all the required overriding
have to be done.
Design 3: Interfaces of Changing Behaviours
Design 3: Flaw
● No code reuse
● The fly method has to be implemented in all the subclasses even
for the Ducks with the same fly method.
● For most of the modifications, we will have to make the
modifications in multiple subclasses
The Final Solution
● The Duck subclasses will use interface for the behaviors
(FlyBehavior, QuackBehavior)
● The concrete behavior is coded in the class that implements the
above interfaces
● The actual behavior is not locked in the Duck subclasses
The Final Solution
Final Solution: Duck class
public abstract class Duck {
FlyBehavior flyBehavior;
QuackBehavior quackBehavior;
public Duck() { }
public abstract void display();
public void performFly() {
flyBehavior.fly();
}
public void performQuack() {
quackBehavior.quack();
}
}
public void swim() {
System.out.println("All ducks
float, even decoys!");
}
}
Final Solution: Mallard Duck
public class MallardDuck extends Duck {
public MallardDuck() {
quackBehavior = new Quack();
flyBehavior = new FlyWithWings();
}
https://github.com/bethrobson/Head-First-Design-Patterns/tree/master/src/headfirst/designpatterns/strate
gy
What we were discussing till now?
Source: https://en.wikipedia.org/wiki/Strategy_pattern
Strategy Design Pattern
The behaviors of a class should not be inherited. Instead, they should
be encapsulated using interfaces.
Types of Design Patterns
● Creational
Provides object or class creation mechanism
● Structural
assemble object and classes into a structure ensuring that the
structure should be flexible and efficient
● Behavioural
Manages how one class communicates with another
Creational Design Pattern
Factory Method Pattern
Separates out the creation of objects/instances.
Making Pizza Example
Pizza orderPizza(String type) {
Pizza orderPizza() {
Pizza pizza;
Pizza pizza = new Pizza();
if (type.equals("cheese")) {
pizza.prepare(); pizza = new CheesePizza();
pizza.bake(); } else if (type.equals("greek") {
pizza.cut(); pizza = new GreekPizza();
pizza.box(); } else if (type.equals("pepperoni") {
return pizza pizza = new PepperoniPizza();
} }
pizza.prepare();
pizza.bake();
pizza.cut();
pizza.box();
return pizza
Instantiation of different
} classes for different types
of pizzas
There is pressure to add more pizza types !!
if (type.equals("cheese")) {
pizza = new CheesePizza();
} else if (type.equals("greek") {
pizza = new GreekPizza();
} else if (type.equals("pepperoni") {
pizza = new PepperoniPizza();
} else if (type.equals("clam") {
pizza = new ClamPizza();
} else if (type.equals("veggie") {
pizza = new VeggiePizza(); This keeps o g o n
} and some et mod fied
Encapsulating Object Creation
Pizza orderPizza(String type) { Pizza orderPizza(String type) {
Pizza pizza; Pizza pizza;
if (type.equals("cheese")) {
pizza = new CheesePizza();
} else if (type.equals("greek") {
pizza = new GreekPizza();
} else if (type.equals("pepperoni") {
pizza = new PepperoniPizza();
} pizza.prepare();
pizza.bake();
pizza.prepare(); pizza.cut();
pizza.bake(); pizza.box();
pizza.cut(); return pizza
pizza.box(); }
return pizza
}
Simple Pizza Factory
public class SimplePizzaFactory {
public Pizza createPizza(String type) {
Pizza pizza = null;
if (type.equals("cheese")) {
pizza = new CheesePizza();
} else if (type.equals("pepperoni")) {
pizza = new PepperoniPizza();
} else if (type.equals("clam")) {
pizza = new ClamPizza();
} else if (type.equals("veggie")) {
pizza = new VeggiePizza();
}
return pizza;
}
How does PizzaStore looks like?
Class Diagram of Pizza Store
Different Style Pizza
Pizza Class Diagram
Cheese
Factory Classes for Different Styles
A Different Design to Manage Styles
Allow Subclasses to Decide
Product and Creator Classes
Another Example: Shapes
Source: https://www.tutorialspoint.com/design_pattern/factory_pattern.htm
Abstract Factory Pattern Factory Method pattern is
responsible for creating products
that belong to one family, while
Abstract Factory pattern deals with
multiple families of products.