package devopsdistilled.operp.client.abstracts;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import devopsdistilled.operp.server.data.entity.Entiti;
import devopsdistilled.operp.server.data.service.EntityService;

public abstract class AbstractEntityModel<E extends Entiti, ES extends EntityService<E, ID>, EO extends EntityObserver<E>, ID extends Serializable>
		extends AbstractModel<EO> implements EntityModel<E, ES, EO, ID> {

	protected List<E> entities;

	public AbstractEntityModel() {
		entities = new LinkedList<>();
	}

	@Override
	public List<E> getEntities() {
		return entities;
	}

	@Override
	public void setEntities(List<E> entities) {

		this.entities = entities;
		notifyObservers();

	}

	@Override
	public void update() {
		setEntities(getService().findAll());
	}

	@Override
	public void notifyObservers() {
		for (EO observer : observers) {
			observer.update(getEntities());
		}
	}

	@Override
	public void registerObserver(EO observer) {
		super.registerObserver(observer);
		update();
		observer.update(getEntities());
	}
}

@@ -71,16 +71,101 @@
 izable;%0A
+import java.lang.reflect.InvocationTargetException;%0Aimport java.lang.reflect.Method;%0A
 import j
@@ -448,19 +448,16 @@
 Observer
-%3CE%3E
 , ID ext
@@ -980,190 +980,522 @@
 ) %7B%0A
+%0A
 %09%09%09
-observer.update(getEntities());%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public void registerObserver(EO observer) %7B%0A%09%09super.registerObserver(observer);%0A%09%09update();%0A%09%09observer.update(getEntities());%0A%09%7D
+Method updateMethod = getUpdateMethod();%0A%09%09%09try %7B%0A%09%09%09%09updateMethod.invoke(observer, getEntities());%0A%09%09%09%7D catch (IllegalAccessException %7C IllegalArgumentException%0A%09%09%09%09%09%7C InvocationTargetException e) %7B%0A%09%09%09%09e.printStackTrace();%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public void registerObserver(EO observer) %7B%0A%09%09super.registerObserver(observer);%0A%09%09update();%0A%09%7D%0A%0A%09protected abstract Class%3CEO%3E getObserverClass();%0A%0A%09private Method getUpdateMethod() %7B%0A%09%09Method%5B%5D methods = getObserverClass().getMethods();%0A%09%09return methods%5B0%5D;%0A%09%7D%0A
 %0A%7D%0A

Add abstract getObserverClass() and use it for dynamic updateMethods() invocation