Drawbacks of Singleton Design Pattern | clean code in swift | advance swift tutorial

Поділитися
Вставка
  • Опубліковано 13 вер 2019
  • The drawback of Singleton design pattern is that it’s easy to use, and since it’s easy to use and can be accessed from anywhere within your application, freshers and even experienced developers tend to overuse this design pattern.
    Nowadays drawback of singleton class or singleton pattern is the most commonly asked interview question and codecat15 swift video tutorial will help you know the drawback of this design pattern in-depth covering all major points.
    This swift video from codecat15 talks about how the singleton pattern is abused and used in the most unethical way and covers the drawbacks of using the singleton design pattern.
    You should be careful about when to use Singleton Pattern and where because of the nature of the singleton class in general. I hope this swift tutorial gives you more clarity about the singleton class or singleton design pattern.
    This tutorial uses swift 5 version but it does not matter if you use swift 5, swift 4, or swift 3 because the singleton pattern in swift is not a feature of swift but a part of creational design pattern and in the future, we will learn more on design patterns with simple and easy to remember examples that do not follow any bookish definition.
    I hope this video gives you clarity and insights about singleton.
    Please subscribe to the channel if this video has helped you and connect with me on social media
    Email: codecat15@gmail.com
    Twitter: / codecat15
    Facebook: / code.cat.792
    Github: github.com/codecat15
    Link of ppt used in the video: drive.google.com/open?id=1rHT...

КОМЕНТАРІ • 34

  • @hamayunzeb8765
    @hamayunzeb8765 Рік тому

    Outstanding

  • @keertikagupta
    @keertikagupta 3 роки тому +1

    great!! nicely explained. Thank you.

  • @aarukiapniduniya
    @aarukiapniduniya 2 роки тому +1

    The way of explaining is just mind blowing... Good job... I really appreciate your work.... Last but not list bohat bohat Shukriya apka ....

    • @CodeCat15
      @CodeCat15  2 роки тому

      Thank you Aarti, I hope this was helpful and please feel free to ask questions on this topic if any.

  • @wolvrG
    @wolvrG 3 роки тому +1

    A very clear understanding. Really liked the way of teaching.

    • @CodeCat15
      @CodeCat15  3 роки тому

      Glad to hear that! and welcome to the channel

  • @chetanaggarwal119
    @chetanaggarwal119 3 роки тому +1

    good job mahn!! well explained!!

    • @CodeCat15
      @CodeCat15  3 роки тому

      Thanks Chetan, I am glad you this video was helpful :)

  • @pandiangurunathan5039
    @pandiangurunathan5039 3 роки тому

    Awesome... keep going

  • @avinashsakroji1811
    @avinashsakroji1811 Рік тому +1

    Thank you for this explanation.

    • @CodeCat15
      @CodeCat15  Рік тому

      You are welcome, do share the channel with your iOS group and feel free to ask questions if any

  • @shiviparashar7419
    @shiviparashar7419 3 роки тому +1

    Please make a video on VIPER.

  • @shiviagarwal9134
    @shiviagarwal9134 2 роки тому +2

    Hi Ravi, Thanks for such an informative video!! In the video you mentioned that you use singleton to write debug logs for your app. Could you please make a video on how can we do that?

    • @CodeCat15
      @CodeCat15  2 роки тому

      I think I have that logger shared in one of my Git repos I’ll see what I can do for that video but to be honest the logger just writes to a file in the document folder and when the user sends a bug report we just attach that log file you can say this is like the most vanilla version of logging than using something like firebase analytics or some other tools

    • @vyankateshshivnikar7932
      @vyankateshshivnikar7932 Рік тому

      Agree

  • @krishnasadhu4840
    @krishnasadhu4840 2 роки тому

    great

  • @vyankateshshivnikar7932
    @vyankateshshivnikar7932 Рік тому +1

    Awesome

    • @CodeCat15
      @CodeCat15  Рік тому

      Thanks 👍

    • @vyankateshshivnikar7932
      @vyankateshshivnikar7932 Рік тому +1

      @@CodeCat15 Ravi can you please make video on Push Notifications? and rich push notifications ?

    • @vyankateshshivnikar7932
      @vyankateshshivnikar7932 Рік тому +1

      @@CodeCat15 So requesting one playlist for push notification and one for Certificates like distribution certificate, provisioning profile, APNs certificate etc.

  • @sridivyabolla3543
    @sridivyabolla3543 2 роки тому

    Hi,
    Using singleton with dispatch_once for db connections and operations, other than that it is a global instance as explained in the video, can there be any other reasons not to use singleton instance? DB connections created are being closed immediately once the query is executed. Here, I am not using CoreData framework but using a custom plugin or framework to interact directly with Sqlite database.

  • @mukulbakshi28
    @mukulbakshi28 4 роки тому

    @Code Cat How you manage the Data modal of a user which you receives from an API call after login or signup, like as we always need a user id and name in many different API calls or profile section, so if we do not make singleton for that then what's the alternative you have in this scenario for accessing the user data.

    • @CodeCat15
      @CodeCat15  4 роки тому +4

      Thanks for the question @Mukul and welcome to the channel. I use userdefaults for this, and on logout i wipe out the user-default userId, If you want to keep an entire object then in that case use codable encode the object using JSONEncoder and store it inside the user-default and when you retrieve it back just decode the values. I will be showing this in my upcoming tutorial on MVVM pattern, feel free to ask more questions if you have would love to answer them and share this channel with your iOS group too :)

    • @chetanaggarwal119
      @chetanaggarwal119 3 роки тому

      @@CodeCat15 if the user info such as user state is been used by application very extensively then won't user default becomes a costly option??

  • @aarukiapniduniya
    @aarukiapniduniya 2 роки тому +1

    Can I have more examples where I can use singleton class? Like I had faced a question where singleton can be good example?

    • @CodeCat15
      @CodeCat15  2 роки тому

      I mostly use singleton as utility class that I can use across my application, like HttpUtility is one of them.

  • @diliptilonia
    @diliptilonia 4 роки тому +1

    sir @CodeCat could you please share your singleton file which you use in debug log

    • @CodeCat15
      @CodeCat15  4 роки тому +1

      Hey @Dilip welcome to the channel, I have just uploaded the singleton class in my git and google drive
      Google drive link: drive.google.com/open?id=1mUPzJTGTFUzK4-Jn09r-p4QvjRDjI4pp
      Github link: github.com/codecat15/UA-cam-tutorial/tree/master/SingletonClassDemo
      These links are available in my singleton videos as well. By the way if you have any question on this topic then please feel free to ask and do share this channel with your iOS group and ask them to subscribe as well :)

  • @natureloverspakistan
    @natureloverspakistan 4 роки тому

    i use singleton pattern for socket, progress loader, and temporary save object on application load, object is destroy when u kill the application

    • @CodeCat15
      @CodeCat15  4 роки тому +2

      Singleton should be used but there should be a guideline to it, i will always avoid using singleton and still my app works fine but the problem is overuse of this pattern which ultimately results in an abuse. There is a saying in hindi “jaha pe sui (needle) ka kaam hai vaha talvar use kyu karna”

    • @natureloverspakistan
      @natureloverspakistan 4 роки тому +1

      you are right sir ... thanks for your guidance .. i have done a lot improvements in my coding style after watching your tutorials.

    • @CodeCat15
      @CodeCat15  4 роки тому +3

      Aare bhai sir mat bolo simply codecat15 or ravi is fine :) If you want me to have a look at your code then let me know, aap aapka code github pe share kar sakte hai .
      Complex code karne mai koi logic nahi lagta aap easily kar sakte ho, koi bhi kar sakta hai but to simplify the code it takes efforts :)
      I want you to check this video of mine to understand why I want to follow process and good design, hope this helps you
      ua-cam.com/video/nA38yONh30w/v-deo.html

  • @GaneshKumar-xp6zp
    @GaneshKumar-xp6zp 3 роки тому

    Better Avoid Hindi.

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      I am sorry if the video's language was the issue in understanding the concept. As you can see majority of the channel content is in Hindi and it's helping them to get a clear understanding of the topic. What can I do to make things better for you apart from the language, if you need captions for any specific video just drop a comment and I will work towards it Ganesh.