Skip to content

Commit 6bd09ce

Browse files
author
Grzegorz Piwowarek
committed
Refactor Reflection examples
1 parent 89944e9 commit 6bd09ce

8 files changed

Lines changed: 384 additions & 372 deletions

File tree

‎reflection/pom.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<artifactId>maven-compiler-plugin</artifactId>
1313
<version>3.3</version>
1414
<configuration>
15-
<source>7</source>
16-
<target>7</target>
15+
<source>8</source>
16+
<target>8</target>
1717
</configuration>
1818
</plugin>
1919
</plugins>
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
package com.baeldung.reflection;
22

3-
public abstract class Animal implements Eating{
4-
public static final String CATEGORY = "domestic";
5-
private String name;
3+
public abstract class Animal implements Eating {
64

7-
public Animal(String name) {
8-
this.name = name;
9-
}
5+
public static final String CATEGORY = "domestic";
106

11-
public String getName() {
12-
return name;
13-
}
7+
private String name;
148

15-
public void setName(String name) {
16-
this.name = name;
17-
}
9+
public Animal(String name) {
10+
this.name = name;
11+
}
1812

19-
public String makeSound() {
20-
return getSound();
21-
}
13+
public String getName() {
14+
return name;
15+
}
2216

23-
protected abstract String getSound();
17+
public void setName(String name) {
18+
this.name = name;
19+
}
20+
21+
public String makeSound() {
22+
return getSound();
23+
}
24+
25+
protected abstract String getSound();
2426

2527
}
Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
package com.baeldung.reflection;
22

33
public class Bird extends Animal {
4-
private boolean walks;
5-
public Bird() {
6-
super("bird");
7-
}
8-
public Bird(String name, boolean walks) {
9-
super(name);
10-
setWalks(walks);
11-
}
12-
public Bird(String name) {
13-
super(name);
14-
}
15-
16-
@Override
17-
public String eats() {
18-
return "grains";
19-
}
20-
21-
@Override
22-
protected String getSound() {
23-
return "chaps";
24-
}
25-
26-
public boolean walks() {
27-
return walks;
28-
}
29-
30-
public void setWalks(boolean walks) {
31-
this.walks = walks;
32-
}
4+
private boolean walks;
5+
6+
public Bird() {
7+
super("bird");
8+
}
9+
10+
public Bird(String name, boolean walks) {
11+
super(name);
12+
setWalks(walks);
13+
}
14+
15+
public Bird(String name) {
16+
super(name);
17+
}
18+
19+
@Override
20+
public String eats() {
21+
return "grains";
22+
}
23+
24+
@Override
25+
protected String getSound() {
26+
return "chaps";
27+
}
28+
29+
public boolean walks() {
30+
return walks;
31+
}
32+
33+
public void setWalks(boolean walks) {
34+
this.walks = walks;
35+
}
3336
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package com.baeldung.reflection;
22

33
public interface Eating {
4-
String eats();
4+
String eats();
55
}
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
package com.baeldung.reflection;
22

3-
public class Goat extends Animal implements Locomotion{
3+
public class Goat extends Animal implements Locomotion {
44

5-
public Goat(String name) {
6-
super(name);
7-
}
5+
public Goat(String name) {
6+
super(name);
7+
}
88

9-
@Override
10-
protected String getSound() {
11-
return "bleat";
12-
}
9+
@Override
10+
protected String getSound() {
11+
return "bleat";
12+
}
1313

14-
@Override
15-
public String getLocomotion() {
16-
return "walks";
17-
}
14+
@Override
15+
public String getLocomotion() {
16+
return "walks";
17+
}
1818

19-
@Override
20-
public String eats() {
21-
return "grass";
22-
}
19+
@Override
20+
public String eats() {
21+
return "grass";
22+
}
2323

2424
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package com.baeldung.reflection;
22

33
public interface Locomotion {
4-
String getLocomotion();
4+
String getLocomotion();
55
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.baeldung.reflection;
22

33
public class Person {
4-
private String name;
5-
private int age;
4+
private String name;
5+
private int age;
66
}

0 commit comments

Comments
 (0)