Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concept of complexity explained #6

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="/DesignPatternsJava9/src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Compiled class file
.idea/*
*.class

# Log file
*.log

*.iws
# BlueJ files
*.ctxt

Expand Down
15 changes: 15 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>DesignPatternsJava9</name>
<comment/>
<projects/>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments/>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
6 changes: 6 additions & 0 deletions DesignPatternsJava9.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<component inheritJdk="true">
<output-test url="file:https://$MODULE_DIR$/bin/test/DesignPatternsJava9"/>
<exclude-output/>
<contentEntry url="file:https://$MODULE_DIR$"/>
</component>
13 changes: 13 additions & 0 deletions DesignPatternsJava9.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file:https://$MODULE_DIR$/bin/production/DesignPatternsJava9" />
<output-test url="file:https://$MODULE_DIR$/bin/test/DesignPatternsJava9" />
<exclude-output />
<content url="file:https://$MODULE_DIR$">
<sourceFolder url="file:https://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
# DesignPatternsJava9
This repo consists Gang of Four Design patterns code on Java 9. Each branch in the repository has code of 1 design pattern. Switch repository to try out different design patterns.
# What is Cyclomatic Complexity?
Cyclomatic complexity is a source code complexity measurement that is being correlated to a number of coding errors. It is calculated by developing a Control Flow Graph of the code that measures the number of linearly-independent paths through a program module.

Lower the Program's cyclomatic complexity, lower the risk to modify and easier to understand.
Cyclomatic complexity = E - N + 2*P
where,
* E = number of edges in the flow graph.
* N = number of nodes in the flow graph.
* P = number of nodes that have exit points


If the decision points are more, then complexity of the program is more. If program has high complexity number, then probability of error is high with increased time for maintenance and trouble shoot.
#### Try to write linear code, which means wrap logic in reusable methods and use them.

### Learn Design Patterns with Java by Aseem Jain
This repository contains working project code used in video Course by Packt Publication with title "Learn Design Patterns with Java " authored by "Aseem Jain".

### Course link:
https://www.packtpub.com/application-development/learn-design-patterns-java-9-video

### ![ https://in.linkedin.com/in/premaseem](https://github.com/premaseem/DesignPatternsJava9/blob/master/linkedin.png "https://in.linkedin.com/in/premaseem") Profile: https://in.linkedin.com/in/premaseem

### Authors blog on design patterns:
https://premaseem.wordpress.com/category/computers/design-patterns/

### Software Design pattern community face book page:
https://www.facebook.com/DesignPatternGuru/
53 changes: 53 additions & 0 deletions src/CyclomatricComplexity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
@author: Aseem Jain
@title: Design Patterns with Java 9
@link: https://premaseem.wordpress.com/category/computers/design-patterns/
*/
public class CyclomatricComplexity {

/*
Problem Statement: Need to print biggest number from given numbers
*/

public static void main (String[] args) {

Integer a=7,b=4,c=10,d=18;

if (a > b) {
if(a > c){
if (a >d){
System.out.println(a+ " is biggest");
}
}
}

if (b > c) {
if(b > d){
if (b >a){
System.out.println(b+ " is biggest");
}
}
}

if (c > b) {
if(c > a){
if (c >d){
System.out.println(c+" is biggest");
}
}
}

if (d > b) {
if(d > c){
if (d >a){
System.out.println(d+" is biggest");
}
}
}
}
}

// Take Away:
// If the decision points are more, then complexity of the program is more.
// If program has high complexity number, then probability of error is high
// with increased time for maintenance and trouble shoot.
35 changes: 35 additions & 0 deletions src/CyclomatricSimplicity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/*
@author: Aseem Jain
@title: Design Patterns with Java 9
@link: https://premaseem.wordpress.com/category/computers/design-patterns/
*/
public class CyclomatricSimplicity {

/*
Problem Statement: Need to print biggest number from given numbers
*/

public static void main (String[] args) {

Integer a=7,b=4,c=10,d=18;
// Event when we need to modify parameter, things can be done
// with minimal code changes

PrintBiggestNumber(a,b,c,d);
}

private static void PrintBiggestNumber (Integer... numbers) {
System.out.println();
List list = Arrays.asList(numbers);
Comparable max = Collections.max(list);
System.out.println(max + " is biggest (KISS)");
}
}

// Take Away:
// KISS - Keep it simple stupid.
// Design clean dry less code which can absorb changes.