Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8155629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:43:29+00:00 2026-06-06T16:43:29+00:00

My question is I wanna apply strategy pattern to save log from Image above

  • 0

My question is I wanna apply strategy pattern to save log

enter image description here

from Image above

I will use replace my class to image

Context = Log Class
Istrategy = ILog

concreteStrategyA = CreateSituation

concreteStrategyB = NameSituation

concreteStrategyC = StatusSituation

[Additional from image]

concreteStrategyD = PriceSituation

concreteStrategyE = DiscountSituation

In ILog have these method
SaveLog(Log log);

each concreteStrategyA,B,C,D,E implement ILog

public class CreateSituation : ILog

{

public void SaveLog(Log log)

{

    using(var context = new ProductContext())

    {

      log.Message = "This product is created";

      context.productLog.InsertonSubmit(log);

      context.submitChange();

    }

}

}

public class NameSituation : ILog

{

public void SaveLog(Log log)

{

    using(var context = new ProductContext())

    {

      log.Message = "this produce has updated name from \"oldProduct\" to \"newProduct\"";

      context.productLog.InsertonSubmit(log);

      context.submitChange();

    }

}

}

public class StatusSituation : ILog

{

public void SaveLog(Log log)

{

    using(var context = new ProductContext())

    {

      log.Message = "this produce has updated status from \"In stock\" to \"Sold Out\"";

      context.productLog.InsertonSubmit(log);

      context.submitChange();

    }

}

}

public class PriceSituation : ILog

{

public void SaveLog(Log log)

{

    using(var context = new ProductContext())

    {

      log.Message = "this produce has updated price from $10 to $150";

      context.productLog.InsertonSubmit(log);

      context.submitChange();

    }

}

}

public class DiscountSituation : Ilog

{

public void SaveLog(Log log)

{

    using(var context = new ProductContext())

    {

      log.Message = "this product has updated discount price from $0 to $20";

      context.productLog.InsertonSubmit(log);

      context.submitChange();

    }

}

}

In the future can have more than present situation

and these classes that I show i a good way to solve these problem

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:43:31+00:00Added an answer on June 6, 2026 at 4:43 pm

    Yes, this is a scenario that could use a strategy pattern.

    However, to me it seems to be a just little bit too much to use a completely different logger instance per logging scenario. But without knowing your architecture this is only my personal gut feeling.

    As an alternative approach I could imagine implementing a factory for just assembling the appropriate logging message, depending on the logging situation.

    [EDIT]

    Additionally I would recommend using some framework like log4net that make logging very easy and intuitive. log4net, for example, differentiates between several logging levels like WARN, INFO, DEBUG, ERROR,orFATAL that allow you to fine-tune your output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wanna ask this question. Can I use detailTextLabel in a Custom Cell? I
I have a question about NSUserDefault. Currently, i wanna write a function which save
Question: I use the bidirectional dicionary class I found here: Bidirectional 1 to 1
Simple question, I have code like this: class Context[A] { def t: A }
This question is not language-aware. I wanna know how can I recognize a returning
I have a question with php. I wanna generate a signature based on some
I am just a beginner in ASP.NET. My question is simple, I wanna add
Question context: let say that there is some really important row in config/locales/en.yml that
Question from Object-Oriented JavaScript book: Imagine Array() doesn't exist and the array literal notation
I want add my page some div and another tags.I wanna give unique class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.