Notes on "Elegant Objects (Volume 1)"

Here is the link to the book. My notes for Chapter - 1.

Never use -er names

A class ..
  • is a factory of objects.
  • makes objects and keeps track of them.
  • is an active manager of objects.
  • should be named after what he is, not after what he does.
A class name that ends with "-er" tells us that this creature is not an object but a collection of procedures..

My Notes
I am not sure how a class keeps track of objects to be honest. And regarding the "-er" classes, we do have Managers in real life, or Controllers. Here is a quotation from the book:
Let 's say you have a list of numbers and an algorithm that tells you which number is prime. Do not call this class Primer or PrimeFinder. Instead, name him PrimeNumbers. PrimeNumbers is a list of numbers, he is a list.
Here is an example I have:
package biz.tugay;
 
/**
 * User: Koray Tugay (koray@tugay.biz)
 * Date: 9/17/2016
 * Time: 8:50 AM
 */
public class Employee {
 
    private String fullname;
    private int level;
 
    public Employee(String fullname, int level) {
        this.fullname = fullname;
        this.level = level;
    }
 
    public String getFullname() {
        return fullname;
    }
 
    public int getLevel() {
        return level;
    }
}
 
package biz.tugay;
 
import java.util.List;
 
/**
 * User: Koray Tugay (koray@tugay.biz)
 * Date: 9/17/2016
 * Time: 8:51 AM
 */
public class Manager {
 
    private List<Employee> employees;
 
    public Manager(List<Employee> employees) {
        this.employees = employees;
    }
 
    public void payWages() {
        for (Employee employee : employees) {
            int amountToBePaid;
            switch (employee.getLevel()) {
                case 1:
                    amountToBePaid = 100;
                    break;
                case 2:
                    amountToBePaid = 200;
                    break;
                default:
                    amountToBePaid = 25;
            }
            payWage(employee, amountToBePaid);
        }
    }
 
    private void payWage(Employee employee, int amount) {
        final String fullname = employee.getFullname();
        System.out.println("An amount of: " + amount + " has been paid to: " + fullname);
    }
}
 
package biz.tugay;
 
import java.util.Arrays;
 
public class Main {
 
    public static void main(String[] args) {
        final Employee korayTugay = new Employee("Koray Tugay", 1, "12345");
        final Employee mickJagger = new Employee("Mick Jagger", 2, "98765");
        final Manager manager = new Manager(Arrays.asList(korayTugay, mickJagger));
        manager.payWages();
    }
}
And the output will be:
An amount of: 100 has been paid to: Koray Tugay
An amount of: 200 has been paid to: Mick Jagger
I guess here the Manager is the Manager? I do not know, honestly. Probably "-er" names are sometimes fine..

Make one constructor primary

In the book it is suggested that a client should be able to create objects from a class as seen below.
public class Main {
    public static void main(String[] args) {
        new Cash(5);
        new Cash("5");
        new Cash(5, "USD");
    }
}
Quoting from the book:
All of these statements should create the same object.
My Notes
Again I am confused here. What if I call the following constructor?
new Cash(5, "EUR");
It should give me the same object with Cash(5) as well which was the same object acquired from Cash(5, "USD") in the first place? How about Cash(5, "Hello world")?

I really do not buy this many constructors, few methods suggestion.

Keep constructors code free

So the author suggests this is good practice:  
public class Main {
    public static void main(String[] args) {
        final App app = new App(new Data(), new Screen());
        app.run();
    }
}
and says
The first step is to instantiate an object; the second step is to allow him to work for us. A constructor should be code free.
My Notes
I do not know. What is the harm in this example?
public class DeltaStore implements Serializable {
 
   public static final String DELTA_STORE_ONLY_IN_INNBOUND_KEY = "deltastore.onlyInInnbound";
   public static final String DELTA_STORE_INSERTED_KEY = "deltastore.inserted";
   public static final String DELTA_STORE_UPDATED_KEY = "deltastore.updated";
 
   private final String boType;
 
   private final List<String> onlyInInnbound = new ArrayList<String>();
   private final List<String> updated = new ArrayList<String>();
   private final List<String> inserted = new ArrayList<String>();
 
   public DeltaStore(List<Operation> operations, List<BaseBusinessObject> boList, String boType) {
       this.boType = boType;
 
       for (BaseBusinessObject baseBusinessObject : boList) {
           onlyInInnbound.add(baseBusinessObject.getBusinessKey());
       }
 
       for (Operation operation : operations) {
           final String businessKey = operation.getData().getBusinessKey();
           if (!onlyInInnbound.contains(businessKey)) {
               inserted.add(businessKey);
           }
           if (onlyInInnbound.contains(businessKey)) {
               updated.add(businessKey);
               onlyInInnbound.remove(businessKey);
           }
       }
   }
 
   public DeltaStore(Set<ApplicationLogMessage> messages, String boType) {
       this.boType = boType;
       for (ApplicationLogMessage applicationLogMessage : messages) {
           final String messageKey = applicationLogMessage.getMessageKey();
           final String bKey = applicationLogMessage.getParam0();
           if (messageKey.equals(DELTA_STORE_ONLY_IN_INNBOUND_KEY)) {
               onlyInInnbound.add(bKey);
           }
           if (messageKey.equals(DELTA_STORE_UPDATED_KEY)) {
               updated.add(bKey);
           }
           if (messageKey.equals(DELTA_STORE_INSERTED_KEY)) {
               inserted.add(bKey);
           }
       }
   }
 
   public List<String> getOnlyInInnbound() {
       return onlyInInnbound;
   }
 
   public List<String> getUpdated() {
       return updated;
   }
 
   public List<String> getInserted() {
       return inserted;
   }
 
   public String getBoType() {
       return boType;
   }
}