fix: Interfaces and Abstract classes

This commit is contained in:
Sami 2024-11-20 10:33:28 -05:00
parent 6b7d95a461
commit 8292e4e272
17 changed files with 128 additions and 0 deletions

29
Interfaces/.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

3
Interfaces/.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -0,0 +1,7 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<ScalaCodeStyleSettings>
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
</ScalaCodeStyleSettings>
</code_scheme>
</component>

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GitToolBoxBlameSettings">
<option name="version" value="2" />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Interfaces.iml" filepath="$PROJECT_DIR$/Interfaces.iml" />
</modules>
</component>
</project>

6
Interfaces/.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

11
Interfaces/Interfaces.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,14 @@
public abstract class CountingSender {
private String prefix;
private int counter;
public CountingSender(String prefix){
this.prefix = prefix;
}
public void Greet(String message){
this.counter ++;
this.write("%d: %s,%s".formatted(this.counter, this.prefix, message));
}
abstract void write(String message);
}

View File

@ -0,0 +1,11 @@
public class MessageSender extends CountingSender {
public MessageSender(String prefix) {
super(prefix);
}
@Override
void write(String message) {
System.out.println("- " + message);
}
}

View File

@ -0,0 +1,6 @@
public interface Sender {
void send(String message);
default void Greet(String prefix, String message){
send(prefix + " ---- " + message);
}
}

View File

@ -0,0 +1,16 @@
public class TextSender implements Sender{
@Override
public void send(String message) {
System.out.println(message);
}
public static void main(String[] args) {
var txtSender = new TextSender();
txtSender.Greet("Hello", "Naruto");
System.out.println("---");
var msgSender = new MessageSender("Hello");
msgSender.Greet(" Sasuke");
msgSender.Greet(" Ichigo");
}
}