+1 (315) 557-6473 

Program To Implement Decorator Observer and Strategy Pattern Using Java Programming Language Assignment Solutions.


Instructions

Objective
Write a program to implement decorator observer and strategy pattern in Java programming language.

Requirements and Specifications

## Running with server
You can optionally turn on and run as real http server by running the main method in the Server class.
## Overview
You are building a simple chat application with 4 endpoints.
/createUser
- takes username/password as post body
- Store password hash
- Do not allow users to create an account if username already taken
/login
- Take username and password as post body
- Lookup userName and hashed password combination
- If Exists create new entry in AuthDao
- Return Set-Cookie header in http response with a custom hash
/getConversations
- Returns all conversations for a user
- User must be authenticated with auth cookie
/getConversation
- Returns all messages between 2 users
- User must be authenticated with auth cookie
- Takes conversationId as get Param
/createMessage
- Created a new message
- If no conversation object exists, create a new one for both users
- Generate a re-usable conversationId
- User must be authenticated with auth cookie
Responses return a JSON object as the body of an http response
Source Code
DECORATOR
package model.decoratorPattern;
import java.awt.*;
public abstract class DecoratorShootable implements Shootable {
    private final Shootable shootable;
    public DecoratorShootable(Shootable shootable) {
        this.shootable = shootable;
    }
    @Override
    public void animate() {
        shootable.animate();
    }
    @Override
    public int getX() {
        return shootable.getX();
    }
    @Override
    public int getY() {
        return shootable.getY();
    }
    @Override
    public void setY(int y) {
        shootable.setY(y);
    }
    @Override
    public Color getColor() {
        return shootable.getColor();
    }
    @Override
    public boolean isEnemy() {
        return shootable.isEnemy();
    }
    @Override
    public int getSize() {
        return shootable.getSize();
    }
    @Override
    public int getStepMove() {
        return shootable.getStepMove();
    }
}
OBSERVER PATTERN
package model.observerPattern;
import model.AbstractRenderable;
import java.awt.*;
public abstract class AbstractHittable extends AbstractRenderable implements HitObserver {
    protected int size;
    protected boolean destroyed;
    public AbstractHittable(int x, int y, Color color, int size) {
        super(x, y, color);
        this.size = size;
        destroyed = false;
    }
    public boolean isDestroyed() {
        return destroyed;
    }
}
BOMB SHOOTER
package model.stratagyPattern;
import model.decoratorPattern.BombShootable;
import model.decoratorPattern.ConcreteShootable;
import model.decoratorPattern.Shootable;
public class BombShooter implements Shooter {
    @Override
    public Shootable shoot(int x, int y) {
        return new BombShootable(new ConcreteShootable(x, y));
    }
}
BOMB SHOOTER
package model.stratagyPattern;
import model.decoratorPattern.ConcreteShootable;
import model.decoratorPattern.Shootable;
public class BulletShooter implements Shooter {
    @Override
    public Shootable shoot(int x, int y) {
        return new ConcreteShootable(x, y);
    }
}
ENEMY SHOOTER
package model.stratagyPattern;
import model.decoratorPattern.ConcreteShootable;
import model.decoratorPattern.EnemyShootable;
import model.decoratorPattern.Shootable;
public class EnemyShooter implements Shooter {
    @Override
    public Shootable shoot(int x, int y) {
        return new EnemyShootable(new ConcreteShootable(x, y));
    }
}
SHOOTER
package model.stratagyPattern;
import model.decoratorPattern.Shootable;
public interface Shooter {
    Shootable shoot(int x, int y);
}