Wiki

Imprimir Propiedades
Bookshop_domain

Now, we have to model the domain that is related to the application. In this case, a set of classes are identified:
 - Product: This is the class of objects that can be present in the warehouse and which can be bought by clients. Products have name, description and availability, which indicates if the product is in the warehouse or not (in case that it has been sold out or has not arrived yet).
 - Book: Just a product with a title and an author.
 - Magazine: A product with a number.
 - Author: This is the class that represents books' authors.
 - Cart: A class that will represent transient cart objects that are stored in each client session. It will be used by the session aspect.
 - Order: A class that holds a product order by buyers. It holds a set of products, such as magazines or books, and requires to be accepted in order to include these products into the warehouse.
 
These classes are written and included in package example.bookshop.domain:


Product.java:

package example.bookshop.domain;

import org.romaframework.aspect.session.SessionAspect;
import org.romaframework.aspect.view.annotation.ViewField;
import org.romaframework.core.flow.ObjectContext;

import example.bookshop.view.domain.HomePageClient;

public class Product {
    public static final String SOLD = "sold";
    public static final String ON_SALE = "on sale";
    public static final String UNAVAILABLE = "unavailable";
   
    protected String name;
    protected String description;
    protected String availability=UNAVAILABLE;
   
    @ViewField(render="label")
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @ViewField(render="label")
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    @ViewField(render="label")
    public String getAvailability() {
        return availability;
    }
    public void setAvailability(String availability) {
        this.availability = availability;
    }

    public String toString() {
        return getName();
    }
}



Book.java:

package example.bookshop.domain;

public class Book extends Product {
    private Author author;
   
    public Author getAuthor() {
        return author;
    }
    public void setAuthor(Author author) {
        this.author = author;
    }
    public String toString() {
        return name;
    }
}


Magazine.java:

package example.bookshop.domain;

public class Magazine extends Product {
    private Integer number;

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }
}



Author.java:

package example.bookshop.domain;

public class Author {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
   
    public String toString() {
        return name;
    }
}



Order.java:

package example.bookshop.domain;

import java.util.ArrayList;

import org.romaframework.aspect.core.annotation.AnnotationConstants;
import org.romaframework.aspect.persistence.PersistenceAspect;
import org.romaframework.aspect.view.annotation.ViewAction;
import org.romaframework.core.flow.ObjectContext;

public class Order {
    public static final String PENDING = "pending";
    public static final String PROCESSED = "processed";
   
    private ArrayList<Product> products = new ArrayList<Product>();
    private String state = PENDING;

    public ArrayList<Product> getProducts() {
        return products;
    }
    public void setProducts(ArrayList<Product> products) {
        this.products = products;
    }
    public String getState() {
        return state;
    }
    public void setState(String state) {
        this.state = state;
    }
}



Cart.java:

package example.bookshop.domain;

import java.util.ArrayList;

import org.romaframework.aspect.persistence.PersistenceAspect;
import org.romaframework.aspect.persistence.QueryByExample;
import org.romaframework.core.flow.ObjectContext;

public class Cart {
    private ArrayList<Product> products = new ArrayList<Product>();

    public ArrayList<Product> getProducts() {
        return products;
    }

    public void setProducts(ArrayList<Product> products) {
        this.products = products;
    }   
}
 

883 Accesos, 0 Ficheros adjuntos 0 Ficheros adjuntos

  • Comentarios