File tree 7 files changed +128
-0
lines changed
core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/demeter
7 files changed +128
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .baeldung .demeter ;
2
+
3
+ public class DemeterApplication {
4
+ public static void main (String [] args ) {
5
+
6
+ Expenses expenses = new Expenses (100 , 10 );
7
+ Employee employee = new Employee ();
8
+ employee .getDepartment ()
9
+ .getManager ()
10
+ .approveExpense (expenses );
11
+
12
+ Manager mgr = new Manager ();
13
+ Employee emp = new Employee (mgr );
14
+ emp .submitExpense (expenses );
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ package com .baeldung .demeter ;
2
+
3
+ public class Department {
4
+
5
+ private Manager manager = new Manager ();
6
+
7
+ public Manager getManager () {
8
+ return manager ;
9
+ }
10
+
11
+ }
Original file line number Diff line number Diff line change
1
+ package com .baeldung .demeter ;
2
+
3
+ public class Employee {
4
+ private Department department = new Department ();
5
+ private Manager manager ;
6
+
7
+ public Employee () {
8
+
9
+ }
10
+
11
+ Employee (Manager manager ) {
12
+ this .manager = manager ;
13
+ }
14
+
15
+ public Department getDepartment () {
16
+ return department ;
17
+ }
18
+
19
+ public void submitExpense (Expenses expenses ) {
20
+ manager .approveExpense (expenses );
21
+ }
22
+
23
+ }
Original file line number Diff line number Diff line change
1
+ package com .baeldung .demeter ;
2
+
3
+ public class Expenses {
4
+
5
+ private double total ;
6
+ private double tax ;
7
+
8
+ public Expenses (double total , double tax ) {
9
+ this .total = total ;
10
+ this .tax = tax ;
11
+ }
12
+
13
+ public double total () {
14
+ return total + tax ;
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ package com .baeldung .demeter ;
2
+
3
+ public class Greetings {
4
+
5
+ HelloCountries helloCountries = new HelloCountries ();
6
+
7
+ private static HelloCountries helloCountriesStatic = new HelloCountries ();
8
+
9
+ public String generalGreeting () {
10
+ return "Welcome" + world ();
11
+ }
12
+
13
+ public String world () {
14
+ return "Hello World" ;
15
+ }
16
+
17
+ public String getHelloBrazil () {
18
+ HelloCountries helloCountries = new HelloCountries ();
19
+ return helloCountries .helloBrazil ();
20
+ }
21
+
22
+ public String getHelloIndia (HelloCountries helloCountries ) {
23
+ return helloCountries .helloIndia ();
24
+ }
25
+
26
+ public String getHelloJapan () {
27
+ return helloCountries .helloJapan ();
28
+ }
29
+
30
+ public String getHellStaticWorld () {
31
+ return helloCountriesStatic .helloStaticWorld ();
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ package com .baeldung .demeter ;
2
+
3
+ public class HelloCountries {
4
+
5
+ public String helloBrazil () {
6
+ return "Hello Brazil" ;
7
+ }
8
+
9
+ public String helloIndia () {
10
+ return "Hello India" ;
11
+ }
12
+
13
+ public String helloJapan () {
14
+ return "Hello Japan" ;
15
+ }
16
+
17
+ public String helloStaticWorld () {
18
+ return "Hello Static World" ;
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ package com .baeldung .demeter ;
2
+
3
+ public class Manager {
4
+
5
+ public void approveExpense (Expenses expenses ) {
6
+ System .out .println ("Expense approved" + expenses .total ());
7
+ }
8
+
9
+ }
You can’t perform that action at this time.
0 commit comments