Skip to content

Commit 4afbe51

Browse files
committed
chore: update code design principle
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
1 parent 56daec6 commit 4afbe51

File tree

12 files changed

+328
-0
lines changed

12 files changed

+328
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
*.class
2+
*.log
3+
~*
4+
5+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
6+
hs_err_pid*
7+
LICENSE
8+
9+
# Maven
10+
target/
11+
.m2/
12+
.mvn/timing.properties
13+
.mvn/wrapper/maven-wrapper.jar
14+
pom.xml.tag
15+
pom.xml.releaseBackup
16+
pom.xml.versionsBackup
17+
pom.xml.next
18+
dependency-reduced-pom.xml
19+
release.properties
20+
buildNumber.properties
21+
settings.xml
22+
.flattened-pom.xml
23+
24+
# Gradle
25+
.gradle/
26+
build/
27+
28+
# Package Files
29+
*.jar
30+
*.war
31+
*.nar
32+
*.ear
33+
*.zip
34+
*.tar.gz
35+
*.rar
36+
37+
# JetBrains
38+
.idea/
39+
*.ipr
40+
*.iws
41+
*.iml
42+
*.releaseBackup
43+
out/
44+
.idea_modules/
45+
atlassian-ide-plugin.xml
46+
47+
# Eclipse
48+
.settings/
49+
.settings
50+
.project
51+
.classpath
52+
.metadata
53+
bin/
54+
tmp/
55+
*.tmp
56+
*.bak
57+
*.swp
58+
*~.nib
59+
local.properties
60+
.settings/
61+
.loadpath
62+
.recommenders
63+
.externalToolBuilders/
64+
*.launch
65+
.factorypath
66+
.target
67+
.springBeans
68+
.recommenders/
69+
.apt_generated/
70+
.apt_generated_test/
71+
.cache-main
72+
.scala_dependencies
73+
.worksheet
74+
75+
# NetBeans
76+
nbproject/private/
77+
build/
78+
nbbuild/
79+
dist/
80+
nbdist/
81+
nbactions.xml
82+
nb-configuration.xml
83+
.nb-gradle/
84+
85+
# MacOS
86+
.DS_Store
87+
profile
88+
89+
# Asciidoctor
90+
.asciidoctor/
91+
92+
# Vim
93+
*.swp
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>expert.os.workshop</groupId>
8+
<artifactId>02-01-code-design-principle</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<name>02-01-code-design-principle</name>
12+
<url>http://www.os.expert</url>
13+
14+
<properties>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
<maven.compiler.source>21</maven.compiler.source>
17+
<maven.compiler.target>21</maven.compiler.target>
18+
<junit.version>5.8.2</junit.version>
19+
<mockito.verson>4.5.1</mockito.verson>
20+
<maven.checkstyle.plugin.version>3.1.0</maven.checkstyle.plugin.version>
21+
<maven.compile.version>3.8.1</maven.compile.version>
22+
<maven.surefire.plugin.version>2.22.2</maven.surefire.plugin.version>
23+
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
24+
<maven-javadoc-plugin.vesion>3.3.0</maven-javadoc-plugin.vesion>
25+
<weld.se.core.version>6.0.1.Final</weld.se.core.version>
26+
</properties>
27+
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.jboss.weld.se</groupId>
31+
<artifactId>weld-se-shaded</artifactId>
32+
<version>${weld.se.core.version}</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.junit.jupiter</groupId>
36+
<artifactId>junit-jupiter-engine</artifactId>
37+
<version>${junit.version}</version>
38+
<scope>test</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.junit.jupiter</groupId>
42+
<artifactId>junit-jupiter-params</artifactId>
43+
<version>${junit.version}</version>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.mockito</groupId>
48+
<artifactId>mockito-core</artifactId>
49+
<version>${mockito.verson}</version>
50+
<scope>test</scope>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.mockito</groupId>
54+
<artifactId>mockito-junit-jupiter</artifactId>
55+
<version>${mockito.verson}</version>
56+
<scope>test</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.assertj</groupId>
60+
<artifactId>assertj-core</artifactId>
61+
<version>3.24.2</version>
62+
<scope>test</scope>
63+
</dependency>
64+
65+
</dependencies>
66+
67+
<build>
68+
<plugins>
69+
<plugin>
70+
<groupId>org.apache.maven.plugins</groupId>
71+
<artifactId>maven-compiler-plugin</artifactId>
72+
<version>${maven.compile.version}</version>
73+
</plugin>
74+
<plugin>
75+
<groupId>org.apache.maven.plugins</groupId>
76+
<artifactId>maven-javadoc-plugin</artifactId>
77+
<version>${maven-javadoc-plugin.vesion}</version>
78+
<executions>
79+
<execution>
80+
<id>attach-javadocs</id>
81+
<goals>
82+
<goal>jar</goal>
83+
</goals>
84+
</execution>
85+
</executions>
86+
<configuration>
87+
<source>${maven.compiler.source}</source>
88+
</configuration>
89+
</plugin>
90+
<plugin>
91+
<groupId>org.apache.maven.plugins</groupId>
92+
<artifactId>maven-source-plugin</artifactId>
93+
<version>${maven-source-plugin.version}</version>
94+
<executions>
95+
<execution>
96+
<id>attach-sources</id>
97+
<goals>
98+
<goal>jar</goal>
99+
</goals>
100+
</execution>
101+
</executions>
102+
</plugin>
103+
<plugin>
104+
<groupId>org.apache.maven.plugins</groupId>
105+
<artifactId>maven-surefire-plugin</artifactId>
106+
<version>${maven.surefire.plugin.version}</version>
107+
</plugin>
108+
</plugins>
109+
</build>
110+
111+
</project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package expert.os.examples;
2+
3+
import jakarta.enterprise.inject.se.SeContainer;
4+
import jakarta.enterprise.inject.se.SeContainerInitializer;
5+
6+
public class App {
7+
8+
public static void main(String[] args) {
9+
try(SeContainer container = SeContainerInitializer.newInstance().initialize()) {
10+
Orchestra orchestra = container.select(Orchestra.class).get();
11+
Instrument keyboard = orchestra.select(InstrumentType.KEYBOARD);
12+
Instrument string = orchestra.select(InstrumentType.STRING);
13+
Instrument percurssion = orchestra.select(InstrumentType.PERCURSSION);
14+
15+
System.out.println("Playing the orchestra");
16+
System.out.println("Keyboard: " + keyboard.play());
17+
System.out.println("string: " + string.play());
18+
System.out.println("percurssion: " + percurssion.play());
19+
20+
}
21+
}
22+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package expert.os.examples;
2+
3+
public interface Instrument {
4+
5+
String play();
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package expert.os.examples;
2+
3+
public enum InstrumentType {
4+
STRING, PERCURSSION, KEYBOARD;
5+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package expert.os.examples;
2+
3+
4+
import jakarta.inject.Qualifier;
5+
6+
import java.lang.annotation.ElementType;
7+
import java.lang.annotation.Retention;
8+
import java.lang.annotation.RetentionPolicy;
9+
import java.lang.annotation.Target;
10+
11+
@Qualifier
12+
@Retention(RetentionPolicy.RUNTIME)
13+
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE})
14+
public @interface MusicInstrument {
15+
16+
InstrumentType value();
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package expert.os.examples;
2+
3+
import jakarta.enterprise.util.AnnotationLiteral;
4+
5+
public class MusicInstrumentLiteral extends AnnotationLiteral<MusicInstrument> implements MusicInstrument {
6+
7+
private final InstrumentType type;
8+
9+
private MusicInstrumentLiteral(InstrumentType type) {
10+
this.type = type;
11+
}
12+
13+
@Override
14+
public InstrumentType value() {
15+
return type;
16+
}
17+
18+
public static MusicInstrumentLiteral of(InstrumentType instrumentType) {
19+
return new MusicInstrumentLiteral(instrumentType);
20+
}
21+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package expert.os.examples;
2+
3+
import jakarta.enterprise.context.ApplicationScoped;
4+
import jakarta.enterprise.inject.Any;
5+
import jakarta.enterprise.inject.Instance;
6+
import jakarta.inject.Inject;
7+
8+
@ApplicationScoped
9+
public class Orchestra {
10+
11+
@Inject
12+
@Any
13+
private Instance<Instrument> instruments;
14+
15+
public Instrument select(InstrumentType type) {
16+
return instruments.select(MusicInstrumentLiteral.of(type)).get();
17+
}
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package expert.os.examples;
2+
3+
@MusicInstrument(InstrumentType.KEYBOARD)
4+
public class Piano implements Instrument {
5+
6+
@Override
7+
public String play() {
8+
return "Piano Sound";
9+
}
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package expert.os.examples;
2+
3+
@MusicInstrument(InstrumentType.STRING)
4+
public class Violin implements Instrument {
5+
@Override
6+
public String play() {
7+
return "Violin Sound";
8+
}
9+
}

0 commit comments

Comments
 (0)