lundi 8 mai 2017

Module Communication between Product Module and User Module

I am thinking to make a communication between Product Module and User Module for frontend. The relation between product and user is each product has a user that creates them. On the other hand, Each user has a list of products created by them.

I would like to ask which approach is the best or do you have any better approach?.

1. Design the module in the frontend completely independent

Product Model (userId and userName is a part of the product attribute)

export class Product {
    name : string;
    description : string;
    userName : string;
    userId : string;
}

ProductPage Component in the frontend

@Component({
    template: '<div  ></div>'
})
export class ProductPage extends Component {
     product: Product;
}

User Model

export class User {
    name : string;
    listOfProducts : string[];
}

In above example, both product and user are not communicating through the model. However, the communication is done in the backend.

Get user for the product info

SELECT product.*, user.id as userId, user.name as userName
from product, user where product.user_id = user.id

2. All the Models resides on the app structure, and communicate to each other.

Product Model (Reside on the app structure)

export class Product {
    name : string;
    description : string;
    user: User;

}

User Model (reside on the app structure)

export class User {
    name : string;
    listOfProducts : Product[];
}

Product page component HTML in the frontend

@Component({
    template: '<div  ></div>'
})
export class ProductPage extends Component {
     userName : string;
     userId : string;

}

App calls the productpage component

<product-page userName= userId=>

I personally think the first approach will be better since it makes the product completely independent from the user. but once we have a lot of data, i think it is always better to nest the models. The other problems in the first approach is I cannot modularize the database module because i treat the database as one entity.

Which one do you think is better? Do you have any way to improve this? or Do you have other approaches you think the best?

Aucun commentaire:

Enregistrer un commentaire