Skip to content

Commit 1abc515

Browse files
committed
Concept of complexity explained
1 parent 9472a4b commit 1abc515

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed

.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
4+
<classpathentry kind="src" path="/DesignPatternsJava9/src"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

.project

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>DesignPatternsJava9</name>
4+
<comment/>
5+
<projects/>
6+
<buildSpec>
7+
<buildCommand>
8+
<name>org.eclipse.jdt.core.javabuilder</name>
9+
<arguments/>
10+
</buildCommand>
11+
</buildSpec>
12+
<natures>
13+
<nature>org.eclipse.jdt.core.javanature</nature>
14+
</natures>
15+
</projectDescription>

DesignPatternsJava9.eml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<component inheritJdk="true">
3+
<output-test url="file://$MODULE_DIR$/bin/test/DesignPatternsJava9"/>
4+
<exclude-output/>
5+
<contentEntry url="file://$MODULE_DIR$"/>
6+
</component>

src/CyclomatricComplexity.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
@author: Aseem Jain
3+
@title: Design Patterns with Java 9
4+
@link: https://premaseem.wordpress.com/category/computers/design-patterns/
5+
*/
6+
public class CyclomatricComplexity {
7+
8+
/*
9+
Problem Statement: Need to print biggest number from given numbers
10+
*/
11+
12+
public static void main (String[] args) {
13+
14+
Integer a=7,b=4,c=10,d=18;
15+
16+
if (a > b) {
17+
if(a > c){
18+
if (a >d){
19+
System.out.println(a+ " is biggest");
20+
}
21+
}
22+
}
23+
24+
if (b > c) {
25+
if(b > d){
26+
if (b >a){
27+
System.out.println(b+ " is biggest");
28+
}
29+
}
30+
}
31+
32+
if (c > b) {
33+
if(c > a){
34+
if (c >d){
35+
System.out.println(c+" is biggest");
36+
}
37+
}
38+
}
39+
40+
if (d > b) {
41+
if(d > c){
42+
if (d >a){
43+
System.out.println(d+" is biggest");
44+
}
45+
}
46+
}
47+
}
48+
}
49+
50+
// Take Away:
51+
// If the decision points are more, then complexity of the program is more.
52+
// If program has high complexity number, then probability of error is high
53+
// with increased time for maintenance and trouble shoot.

src/CyclomatricSimplicity.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.util.Arrays;
2+
import java.util.Collections;
3+
import java.util.List;
4+
5+
/*
6+
@author: Aseem Jain
7+
@title: Design Patterns with Java 9
8+
@link: https://premaseem.wordpress.com/category/computers/design-patterns/
9+
*/
10+
public class CyclomatricSimplicity {
11+
12+
/*
13+
Problem Statement: Need to print biggest number from given numbers
14+
*/
15+
16+
public static void main (String[] args) {
17+
18+
Integer a=7,b=4,c=10,d=18;
19+
// Event when we need to modify parameter, things can be done
20+
// with minimal code changes
21+
22+
PrintBiggestNumber(a,b,c,d);
23+
}
24+
25+
private static void PrintBiggestNumber (Integer... numbers) {
26+
System.out.println();
27+
List list = Arrays.asList(numbers);
28+
Comparable max = Collections.max(list);
29+
System.out.println(max + " is biggest (KISS)");
30+
}
31+
}
32+
33+
// Take Away:
34+
// KISS - Keep it simple stupid.
35+
// Design clean dry less code which can absorb changes.

0 commit comments

Comments
 (0)