Decorator Pattern with Repository Pattern

Asked

Viewed 93 times

2

Guys I have a need here and I’m having some difficulty to implement i have an application with Decorator Pattern and would like to update the data of my Components picking up the information directly from the database, but I’m not finding a cool way to do even using the Repository Pattern.

This is my Component

public abstract class Component
{
    public abstract string GetName();
    public abstract double GetPrice();
    public abstract string GetDescription();
    public abstract int GetMinutesToPrepare();
    public abstract int GetNumberTable();
}

My Concretecomponent

namespace Restaurant.Lib.Components.MainCourse
{
    public class RoastLamb : Dishes
    {
        private string Description = "An Indian roast lamb you can't miss: learn how to prepare a roast leg of lamb indian style, marinated with mixed spices.";
        private int MinutesToPrepare = 30;
        private string Name = "Main Course - Roast Lamb With Indian Spices";
        private int NumberTable = 0;
        private double Price = 53.00;

        public RoastLamb(int numberTable)
        {
            NumberTable = numberTable;
        }

        public override int GetNumberTable() => NumberTable;
        public override string GetDescription() => Description;
        public override int GetMinutesToPrepare() => MinutesToPrepare;
        public override string GetName() => Name;
        public override double GetPrice() => Price;
    }
}

and these data above would like to take from the database.

I made a DAO layer with ado.net same but falls in a circular reference problem because my "Entity" is actually declared inside my Component that is the standard of Decorator.

Someone has a viable solution?

  • 2

    Is there any special reason for you to use this pattern? I found it quite and unnecessarily complex for the purpose you apparently have.

  • My application has as scope a Restaurant and the orders I decided to do this way, for easy increment items to an order for example: Cafe would be a component class and Sugar would be a developer to increase the coffee class and then increase the value and preparation time. The problem that values are variable and not fixed as is.

  • Well, the solution is by external filling via Reflection, but I would need to better understand what your database and application are like to propose something.

  • I still don’t have anything bank for rightly getting in doubt, my application will simply mount the requests instantiating the classes, for example: var desserts = new Applecake(Numbertablerandom); var sugar = new Sugar(desserts); .

  • 1

    Always be cautious when tending to use Reflection. There is little information, and as @Ciganomorrisonmendez spoke it is seeming unnecessary this complexity. Anyway, ever thought about adding a new layer before and making use of DI, or even creating a proxy?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.