vendredi 10 décembre 2021

Can I create an object which I used in main program but with using singleton pattern [closed]

I have a problem in my homework. I want to apply singleton pattern in a project. There is a code here , and I just wanna learn how I can create this object in a class and using singleton design pattern.

FormattedText formattedText = new FormattedText(
                "FABLE",
                new System.Globalization.CultureInfo("en-US"),
                FlowDirection.LeftToRight,
                new Typeface(
                    new System.Windows.Media.FontFamily("Segoe UI"),
                    FontStyles.Normal,
                    FontWeights.Bold,
                    FontStretches.Normal),
                130,
                System.Windows.Media.Brushes.Red,
                dpiInfo.PixelsPerDip);

I just want to know that can I create this "FormattedText formattedText = new FormattedText(); in singleton pattern ?

Like this,

public class SingletonPattern
    {
        private static SingletonPattern instance = new SingletonPattern();
        private SingletonPattern()
        {

        }
        public static SingletonPattern getInstance()
        {
            return FormattedText formattedText = new FormattedText(
                "FABLE",
                new System.Globalization.CultureInfo("en-US"),
                FlowDirection.LeftToRight,
                new Typeface(
                    new System.Windows.Media.FontFamily("Segoe UI"),
                    FontStyles.Normal,
                    FontWeights.Bold,
                    FontStretches.Normal),
                130,
                System.Windows.Media.Brushes.Red,
                dpiInfo.PixelsPerDip);
        }

Can I create this formattedtext in this class ? Thank you so much for helping me.

Aucun commentaire:

Enregistrer un commentaire