-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bef2a5b
commit cc4cc2e
Showing
30 changed files
with
1,435 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-14"> | ||
<attributes> | ||
<attribute name="module" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>hr-domain</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=14 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=14 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=enabled | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore | ||
org.eclipse.jdt.core.compiler.release=disabled | ||
org.eclipse.jdt.core.compiler.source=14 |
31 changes: 31 additions & 0 deletions
31
hr-domain/src/com/example/hr/application/EmployeeApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.example.hr.application; | ||
|
||
import com.example.hr.domain.Employee; | ||
import com.example.hr.events.EmployeeFiredEvent; | ||
import com.example.hr.events.EmployeeHiredEvent; | ||
import com.example.hr.infrastructure.EventPushlisher; | ||
import com.example.hr.repository.EmployeeRepository; | ||
|
||
public class EmployeeApplication { | ||
private EmployeeRepository employeeRepository; | ||
private EventPushlisher eventPushlisher; | ||
|
||
public void setEmployeeRepository(EmployeeRepository employeeRepository) { | ||
this.employeeRepository = employeeRepository; | ||
} | ||
|
||
public void setEventPushlisher(EventPushlisher eventPushlisher) { | ||
this.eventPushlisher = eventPushlisher; | ||
} | ||
|
||
public void hireEmployee(Employee employee) { | ||
employeeRepository.save(employee); | ||
eventPushlisher.publishEvent(new EmployeeHiredEvent("", "employees", employee)); | ||
} | ||
|
||
public void fireEmployee(Employee employee) { | ||
employeeRepository.remove(employee); | ||
eventPushlisher.publishEvent(new EmployeeFiredEvent("", "employees", employee)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.example.hr.domain; | ||
|
||
// Value Object, Immutable | ||
public final class BirthYear { | ||
private final int value; | ||
|
||
private BirthYear(int value) { | ||
this.value = value; | ||
} | ||
|
||
public static BirthYear of(int value) { | ||
if (value > 2020) | ||
throw new IllegalArgumentException("Birt Year cannot be from future"); | ||
return new BirthYear(value); | ||
} | ||
|
||
public int getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + value; | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
BirthYear other = (BirthYear) obj; | ||
if (value != other.value) | ||
return false; | ||
return true; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "BirthYear [value=" + value + "]"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.example.hr.domain; | ||
|
||
public enum Department { | ||
IT, SALES, HR, FINANCE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
package com.example.hr.domain; | ||
|
||
// DDD : Core Domain -> Entity Root -> Aggregate | ||
// Ubiquitous Language: Entity, Entity Root/Aggregate/Value Object | ||
// Bounded Context <--> Sub Domain | ||
// Shortcuts (Eclipse) IntelliJ IDEA | ||
// Ctrl + Shift + + (Zoom In) (Ctrl + Mouse Wheel) | ||
// Ctrl + - (Zoom Out) (Ctrl + Mouse Wheel) | ||
// Ctrl + 1 (Suggestion to remove errors) (Alt + Enter) | ||
// Alt + Shift + S (Generate Source Code) (Alt + Insert) | ||
// Ctrl + Shift + F (Format Source Code) (Ctrl + Alt + L) | ||
public class Employee { | ||
private static final Money MIN_SALARY = Money.of(3_000, MoneyCurrency.TL); | ||
private final TcKimlikNo identityNo; | ||
private FullName fullname; | ||
private Money salary; | ||
private Iban iban; | ||
private final BirthYear birthYear; | ||
private Photo photo; | ||
private boolean fulltime; | ||
private Department department; | ||
|
||
public Employee(TcKimlikNo identityNo, FullName fullname, Money salary, Iban iban, BirthYear birthYear, Photo photo, | ||
boolean fulltime, Department department) { | ||
this.identityNo = identityNo; | ||
this.fullname = fullname; | ||
this.salary = salary; | ||
this.iban = iban; | ||
this.birthYear = birthYear; | ||
this.photo = photo; | ||
this.fulltime = fulltime; | ||
this.department = department; | ||
} | ||
|
||
public Employee(Builder builder) { | ||
this.identityNo = builder.identityNo; | ||
this.fullname = builder.fullname; | ||
this.salary = builder.salary; | ||
this.iban = builder.iban; | ||
this.birthYear = builder.birthYear; | ||
this.photo = builder.photo; | ||
this.fulltime = builder.fulltime; | ||
this.department = builder.department; | ||
} | ||
|
||
public FullName getFullname() { | ||
return fullname; | ||
} | ||
|
||
public void setFullname(FullName fullname) { | ||
this.fullname = fullname; | ||
} | ||
|
||
public Iban getIban() { | ||
return iban; | ||
} | ||
|
||
public void setIban(Iban iban) { | ||
this.iban = iban; | ||
} | ||
|
||
public Photo getPhoto() { | ||
return photo; | ||
} | ||
|
||
public void setPhoto(Photo photo) { | ||
this.photo = photo; | ||
} | ||
|
||
public boolean isFulltime() { | ||
return fulltime; | ||
} | ||
|
||
public void setFulltime(boolean fulltime) { | ||
this.fulltime = fulltime; | ||
} | ||
|
||
public Department getDepartment() { | ||
return department; | ||
} | ||
|
||
public void setDepartment(Department department) { | ||
this.department = department; | ||
} | ||
|
||
public TcKimlikNo getIdentityNo() { | ||
return identityNo; | ||
} | ||
|
||
public Money getSalary() { | ||
return salary; | ||
} | ||
|
||
public BirthYear getBirthYear() { | ||
return birthYear; | ||
} | ||
|
||
public void increaseSalary(double percentage) { | ||
if (percentage <= 0.) | ||
throw new IllegalArgumentException("Percentage cannot be negative or zero"); | ||
this.salary = this.salary.multiply(1. + percentage); | ||
} | ||
|
||
public void decreaseSalary(double percentage) { | ||
if (percentage <= 0.) | ||
throw new IllegalArgumentException("Percentage cannot be negative or zero"); | ||
this.salary = this.salary.multiply(1. - percentage); | ||
if (this.salary.lessThan(MIN_SALARY)) | ||
this.salary = MIN_SALARY; | ||
} | ||
|
||
public void hireToFulltime() { | ||
if (this.fulltime) | ||
throw new IllegalArgumentException("Already full-time"); | ||
this.fulltime = true; | ||
this.increaseSalary(50.); | ||
} | ||
|
||
public void hireToParttime() { | ||
if (!this.fulltime) | ||
throw new IllegalArgumentException("Already part-time"); | ||
this.fulltime = false; | ||
this.decreaseSalary(50.); | ||
} | ||
|
||
public static class Builder { | ||
private final TcKimlikNo identityNo; | ||
private FullName fullname; | ||
private Money salary; | ||
private Iban iban; | ||
private BirthYear birthYear; | ||
private Photo photo; | ||
private boolean fulltime; | ||
private Department department; | ||
|
||
public Builder(String identityNo) { | ||
this.identityNo = TcKimlikNo.of(identityNo); | ||
} | ||
|
||
public Builder fullname(String firstName, String lastName) { | ||
this.fullname = new FullName(firstName, lastName); | ||
return this; | ||
} | ||
|
||
public Builder salary(double value, MoneyCurrency currency) { | ||
this.salary = Money.of(value, currency); | ||
return this; | ||
} | ||
|
||
public Builder iban(String value) { | ||
this.iban = Iban.of(value); | ||
return this; | ||
} | ||
|
||
public Builder birthYear(int value) { | ||
this.birthYear = BirthYear.of(value); | ||
return this; | ||
} | ||
|
||
public Builder photo(byte[] value) { | ||
this.photo = Photo.of(value); | ||
return this; | ||
} | ||
|
||
public Builder fulltime(boolean fulltime) { | ||
this.fulltime = fulltime; | ||
return this; | ||
} | ||
|
||
public Builder department(Department department) { | ||
this.department = department; | ||
return this; | ||
} | ||
|
||
public Employee build() { | ||
return new Employee(this); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.example.hr.domain; | ||
|
||
// Value Object, Immutable | ||
public final class FullName { | ||
private final String first; | ||
private final String last; | ||
|
||
public FullName(String first, String last) { | ||
this.first = first; | ||
this.last = last; | ||
} | ||
|
||
public String getFirst() { | ||
return first; | ||
} | ||
|
||
public String getLast() { | ||
return last; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + ((first == null) ? 0 : first.hashCode()); | ||
result = prime * result + ((last == null) ? 0 : last.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
FullName other = (FullName) obj; | ||
if (first == null) { | ||
if (other.first != null) | ||
return false; | ||
} else if (!first.equals(other.first)) | ||
return false; | ||
if (last == null) { | ||
if (other.last != null) | ||
return false; | ||
} else if (!last.equals(other.last)) | ||
return false; | ||
return true; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "FullName [first=" + first + ", last=" + last + "]"; | ||
} | ||
|
||
} |
Oops, something went wrong.