1. Home
  2. Explore
  3. Computer Science
  4. Software Architecture Interview Questions

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Software Architecture Interview Questions

Transcript

Good morning, good afternoon, good evening from  whichever location you are watching this video   and welcome to Questpond’s YouTube channel and  today what we are doing, today we are going to   go and cover 25 important architecture interview  questions 25 important questions around software   architecture in this 2 hours we will be talking  about how to explain the project architecture we   will be talking about architecture style,  architecture pattern, design patterns, structural, behavioral, creational we will  discuss some questions around singleton pattern.  MVC, MVP, MVVM, layered architecture, tired  architecture and many other things disclaimer,   disclaimer, disclaimer please note by just  watching my videos you are not going to   become an architect you are not going to  go and crack architect interviews it is   very important you should have experience  you should have led your team technically

you should have solved some complex POC you do  understand design patterns you don’t understand   architecture pattern then you will say sir. Video what is this video all about this video   is a revision video see happens is as a senior  Share this video on your Linkedin Account, Email us at questpond@questpond.com and claim free access to Part 2 video on SOLID Principles Interview Questions & Answers but when you go for interview there are questions which comes up. A quick revision is needed and this video will   help you to revise quickly that’s disclaimer  which you need to understand now very quickly   I would like that if you guys can participate in  two or three things in this whole video if you   can do some participation that would help  the community that would help me also for   my further syllabus first thing I am sure  that you are going for architect interview

you have been asked architecture questions  if you can go and put down in the comments   below saying that I was asked this question. I answered like this and this happened that   would not only help the community but also we  are recording further videos in the syllabus I   will try to include them second thing is I am  a teacher at the end of the day I want to know   that are students really enjoying my lessons am I  fruitful isn’t it in this two hours of video let us say that if you are on the 20th minute or let  us say that if you are on the 50th minute if you   can just put down out there and say that ok I am  on the 50th minute and I have completed till here.  This will help me to analyze that how many  people have completed my tutorial until what   level and third important thing is I am giving  you a gift at the last part of this video there   is a beautiful gift out there and I would want  that you should watch the complete video and

check out for the gift let us get started and  here is the syllabus 25 questions I am flashing   on the screen you can see right out there I  am scrolling all the 25 questions which is   going to go and cover the basic questions. MVC, MVP, MVVM, singleton pattern and then   all the other questions what you are seeing on the  screen let us get started with the first question,   let us start with some candidate driven  interview question what exactly is a candidate driven interview question a candidate  driven interview question is a question when you   answer that question depending on your answer  the interviewer can ask you connected questions   or let me use that word over here you can  provoke the interviewer to ask questions.  Accordingly for example if the interviewer asks  you which design pattern have you used in your   project and you say that I have used singleton  pattern I have used repository pattern I have

used CQRS it is very much possible that the  interviewer can ask you questions around   these three patterns now why is it important to  identify candidate driven interview question it   is important to identify candidate driven  interview question because it will help you   to control the interview think about it if  you can provoke the interviewer to ask you.  Questions and that questions which you are good in  you are actually trying to bring the interviewer in your area and that will make your interview  easy and you can easily crack the interview it   is important to identify candidate driven  interview question and this first question   is a candidate driven interview question let  us start with it. This is a banking project   very good project right. Can you explain this  architecture of this project the current project?  Sir MVC but I don’t want a three letter world  right I can see that it’s a very big project

out here can you try to elaborate a little bit  more Model View Controller you are going for   architect interview you are a senior if you are  going to go and answer such kind of one liner   like MVC three layer and MVVM it’s not going to  work remember you are asking for a bigger salary.  Your answer should be elegant your answer should  show of your knowledge your answer should be a   knowledge which shows seniority which shows  authority if I were to answer this question

I would go in such a way what I do over  here is that I would actually glide from   the 50,000 ft. level to the 30,000 ft. level  to the 10,000 ft. level means what first from   the 50,000 ft. level I will talk about the  different layers I have used in my project.  For example I will say that my we had like UI  layer which was made in angular or react whatever   is your framework you have used second we had MVC  layer which is your middle layer then we had the SQL server Database and then we had a cloud in  case if you are using hosting cloud or in case   you have some common layer you want to discuss and  so on first talk about the different pieces and   the layers in your project after that you can go  inside those layers the 30,000 ft. level you can   go and see ok inside the ASP.NET I had used MVC. We had the model we had the view we had the   controller the view had the look and feel it had  the positioning the controller was the binding thing which binds the model and the view and the  model had the business logic now you are going to

the next level the 30,000 ft. level then what you  can do is that you can more glide down and go to   the must be the 10,000 ft. level and talk about  the different patterns you have used you can say   that ok for connecting to the database we have  used a repository patterns to do transactions   we have used unit of work or for example. To centralize object creation you have used   factory pattern or for example for caching and  ETC, you have used singleton pattern you can then go to the patterns out there remember that  whenever you are discussing your architecture   also talk about security if you have used open  ID or if you used Oath or open ID connect start   from the layers go to the architecture  patterns and then talk about the design   pattern remember this is an architect interview  it’s a senior interview your salary is a higher.  End salary your answer should show that  credibility let me try to answer this now that I

have told you the way I will answer it this is how  my answer will be remember that my answer cannot   be your answer you should have your own answer in  your mind because your project is different your   architecture is different this is my answer but I  will say that my project actually consisted of 4   or 5 layers the first one was the UI layer which  had angular then we had the MVC layer the ASP.NET layer where my server components were there. And then we had SQL server and also we had lot   of common components there was also a common  layer then and also we had used MVC pattern we   were following ASP.NET we used the basic model  view controller pattern where in the model had   the business logic the view had the look and  feel the controller was binding both of them   also we had used different design patterns  as well for example repository pattern using

entity framework I was connecting to SQL Server For a caching and for what do you call for caching   and the global objects we have used singleton  pattern and also dependency injection and   factory pattern also we have used and overall for  security we had open ID connect and O auth 2.0 for   which I had used a your active directory the  point is that your answer should be detailed   polished and it should show that elegancy. MVC when we talk about MVC it’s a design pattern,

is it a design pattern I think it’s a design  pattern and what about dependency injection   dependency injection I think dependency  injection it’s an architecture style what   about rest, rest is an architecture  pattern what about factory pattern.  I think factory factory factory pattern I think  is a architecture pattern I think so ok ok we all   try to do this isn’t it we all try to guess  sometimes, sometimes when we don’t know the

answer we try to guess the answer isn’t it but  remember that when you try to guess the answer   what happens is it can build a mistrust  with the interviewer and specifically at   the senior level this trust is so important  this is such an important factor out there   because they think that we are hiring a senior. He should not only be technically competent but   we can trust him we can trust his solution because  he’s going to go and lead a group of people out there I would suggest that when you don’t know  an answer what you should do is you should try   to diplomatically move away saying that I need  to look in to it or I will check out what it   is and then you can say ok like must be at this  moment I am not clear about it I do understand   MVC I know that there is a controller view and  Model I do understand rest that. Rest is there   for network solution where you talk in terms of  resources state statefulness statelessness and

so on what you can do is that you can try to  diplomatically move away from it but see that   you don’t try to guess answers don’t try to give  wrong answers if you try to give wrong answers   wrong vocabulary it will build mistrust and that  can be very bad the whole interview can go good   and there you are with that one mistrust. With that one think the whole interview   can collapse let us now go ahead try to get  the answer what it is architecture style is at the 50,000 ft. level I’m so sorry in between  I will be trying to give you some non-technical   guidance also non-technical things also  don’t feel bad about it definitely this   video I want it to be a pure technical video but  interview is not just about technical things it   is also about non-technical things so sorry  to little bit deviate away from the answer.

First thing if you look at architecture  style it is at the 50,000 ft. level while   architecture pattern goes little bit down  and talks at the structure level and design   pattern talks at the solution level at the code  level at it talks about a specific context let   us try to understand architecture style some  examples of architecture style are rest, rest   is a architecture style I is a architecture style  in case of an architecture style there are just guidelines and principle for example we say ok. Rest is an architecture style which defines how   network application should work how networking  or how two things can communicate with each   other in network in that case rest says that  it should be take stateless rest says that   we should think in terms of resources rest  says that we should have uniform interfaces   like post get put delete or whatever rest  talks about just guidelines and principles.

That is what is termed as architecture style it  just talks about that how your solution should   be shaping up it just talks about the principles  and guidelines while in case of an architecture   pattern it goes at a structure level it goes  at least you will see a block diagram out there   you can see like MVC is an architecture  pattern, MVVM is an architecture pattern,   MVP is an architecture pattern layered  architecture when you say three layer architecture that is again an architecture  pattern in case of an architecture pattern.  There is going to be a controller we know that  there is going to be a view and we know there   is going to be a model now this view it is  built by using HTML or it is built by using   a mobile this model is a class or a function  it does not matter this controller is what   it does like for example in case of ASP.NET  we use the ASP.NET MVC to implement MVC in

the same way you can use something else to you  implement MVC in case of architecture pattern.  He does not talk about that how this will be  implemented you or how the code would be he   does not talk at the code level it just talks  at the broader level at the block diagram level   it just defines the overall structure that is  the architecture pattern design pattern is very   very specific it has a very specific context  I can even that in step ahead and say that in design pattern the code is also very clear  for example some examples of design patterns.  Are factory pattern your iterator pattern your  singleton pattern non-golf means if you look   at the non-golf patterns are like repository  pattern unit of work CQRS these are some of   the patterns in case of a design pattern what  I have seen is things are very clear even at   the code level things are clear or they are in  sync you write either in Java or write either

in C# even the code also looks very same for  example if you look at singleton pattern we say.  It should have a private constructor isn’t it  should have a static keyword lot of things are   clear at the code level and second the context  is very why are we implementing singleton pattern   because we need some common sharing of data we  need a global object why are you implementing   factory pattern to do decoupling we want to  centralize the object creation why are you implementing repository pattern that we can have  an abstraction over the data source there is a   specific context when it comes to design pattern. Architecture style let us try to revise   architecture style just defines the guidelines  and principles architecture pattern defines the   block level but it does not talk at the code  level it is not very specific it is not at a   context level while design pattern has a very  very specific context almost that what the code

can be before we move to questions number three. Here’s a small question or I will rather say let   us have a small discussion on these three things  these three things that is dependency injection   dependency inversion and inversion of control  what do you think these three things are design   pattern, architecture pattern or architecture  style please note dependency injection and   dependency inversion are two different things  they are not same go ahead comment below let us collaborate and let us discuss that these  three things are architecture pattern,   architecture style or design pattern. No architecture interview is complete   without questions on design pattern let  us start with some basic questions of   design pattern and let us then go towards the  advanced once let us first start with what are   design pattern design pattern are time tested  solutions for recurring architecture problems

remember the design pattern does not solve all  the problems of software development it’s only   around the architecture they solve the problem  and they are time tested for recurring problems.  For recurring issues in case of design pattern  you have a problem and then you have a solution   for it whenever you are answering these questions  as a senior please try to use vocabularies which   are in the industry for example you can see these  words like time tested recurring these are some of the vocabularies where the interviewer is looking  from a senior time tasted solution from recurring   architecture problems and when answering this  question please try to know please try to.  Qualify it with some examples of design  pattern for example you can see over here   something like this it is a time tested solution  for recurring architecture problems some of the   examples are for example adapter pattern  if we have incompatible interfaces adapter

pattern solves that for example if you want  to go and iterate over an object sequentially   without exposing the underline representation  underline representation means internally   you don’t want to know it’s a dictionary  internally you don’t want to know it’s a.  List or an array iterator pattern what it does  is it actually helps to you browse sequentially   without exposing the underline representation  template pattern you have a problem where you have a fixed skeleton skeleton of algorithm in a  parent class and you want that for specific steps   the subclass should override it template pattern  repository pattern it helps you to actually.  Provides a separation between the application  logic and data access code it helps you to   abstract and centralize the data aces logic  in an application and by doing you can make   the code more modular more maintainable and  testable make sure when you are qualify when

you are answering this question qualify  it with some examples and there are there   important things to remember whenever you  are giving these examples first thing.  Point number one just try to avoid singleton  pattern I am not saying that don’t say singleton   pattern but what if you want to stand out in  the crowd then don’t do use singleton pattern   as an example because every developer actually  uses this example in interviews second do not just stick to GOF pattern do not just stick  to gang of patterns try to give some non -gof   examples like repository pattern, unit of work,  CQRS, these are some of the non-GOF patterns.  Why because if you see the new era of  micro services and DDD there are many   new design patterns which have come in and  any interviewer would like to hear about it   and most important whatever patterns you mention  out here you should be very confident about it

this part of the answer it depends on you as  a candidate that what you want to answer if   you think no like more than adapter pattern. I understand factory pattern then replace this   answering this question holistically this is how  I will answer it design patterns are time tested   solutions for recurring architecture problems  and some of the examples are for example if   you have incompatible interfaces then adapter  pattern comes to help for example you want to loop through a collection without knowing what is  the type of collection internally iterator pattern   if you want to go and abstract and centralize the  data access logic at one place repository pattern.  What the different types are of deign patterns  primary there are three categories of design   patterns one is a creational category second  one is behavioral category and third one is a   structural category creational category actually  talks about issues around object creation for

example if you say you want to create a single  instance of an object then you have singleton   pattern let us say you have an object and you  want to create a copy of it. You want to create   a clone of it prototype pattern remember that I  have just given some examples out here there are   many more patterns in creational but I have for  this question I have just given two three examples   which I am very comfortable talking second one  is behavioural in case of behavioural the focus is around communication between objects  for example let us say that you have too   many objects who are talking with each other  and because of that things can become chatty.  You have mediator it simplifies the communication  between the classes let us that you have an object   and you want to capture the internal state of the  object. Like old values and new values memento   let us say that you want to create like a workflow  one object doing some task and then passing to the

other object and then the other object chain of  objects then you have chain of responsibility this   is around the what you call architecture issues  or design issues around objects communication.  Then we have structural which talks about the  object composition and structure more more related   around the structure let us say you have to two  classes and they have incompatible interfaces   adapter let us say want to create a composite  object means you have how do you say it let us say that you have a circle inside the circle you have  a rectangle inside the rectangle you have again   have a circle then you have a composite object  decorator you want to add Behavioural dynamically   these are the three different types of. Categories now please note that these   categories have come from gang of 4 really if  you ask me personally in today’s world these   categories don’t actually as a architect  it does not mind to me too much because

new design patterns have been introduced like  repository pattern CQRS aggregate root and   some of these pattern it is very difficult to put  into one of these classes classifications frankly But yes from the interview perspective  remember this three and whenever you are   answering whenever you answering give examples  around it because once you give examples that   send a message to the interviewer saying that  yes this guy understands design pattern and   whatever examples you give you should be very  sure of those examples just revising there   are three different categories of design pattern  creational which talks about the object creation

issues which solves problem around the object  creation issues like prototype and singleton  Behavioural which talks about the communication  between objects like chain of responsibilities   memento and mediator structural which talks about  the object composition and the structural issues   like mismatching of interfaces adapter pattern  composite objects composite pattern if you want   to have composed objects and if you want to  add responsibilities dynamically decorator

Which design pattern have you used in your  project or I will rather say that what are   the different design patterns you are aware  of singleton only singleton any other patterns   singleton pattern yeah that is right but see  at the end of the day when you talk about a   project a project does not work on one design  pattern it needs multiple design patterns.  You can add something more single man singleton  ok this happens with most of the developers most

of the developers love this singleton pattern  I don’t know there are so many patterns out   there this pattern for some reason is talked  or I will say over talked in interviews let me   give you four suggestions of how to answer this  question point number one do not answer singleton   remember it’s a senior interview you stand  outside the crowd stand away from the crowd.  And you should look these things that’s the first  point the second point is that I would suggest that do not talk about golf patterns talk about  non-golf patterns also like repository and unit of   work and aggregate route event sourcing there are  so many other design pattern which have currently   emerged keep those also in mind third point what  I would like to say out here is that only talk   about those patterns which you are confident  and how you can do that if you see any project.  Whatever you have worked I am sure that you must  have used at least 10, 15 patterns unknowingly,

unknowingly go and have a closer look at your  projects see those patterns understand it and talk   about those only in the interview what happens  with that you not only talk confidently but you   also talk naturally that word naturally is very  important and when you start speaking naturally   in an interview specifically in an architect  interview believe me interviewer loves it  An architect interview a senior level interview  should not be just Q&A it should go into a conversation mode in a conversation mode where  both the interviewer as well as the interview   interviewer both of them learn something that’s  the third point and the fourth point I am going   to go and cover 10 patterns out here which  I feel that people use in their projects   but remember that my patterns cannot be  your patterns please see that see your   project closely and come out with some of  those patterns which you are confident on.

But let us here now talk about 10 patterns at  least you know which I will now definitely in   the interview you don’t have so much time  to talk about 10 patterns but I will give   10 patterns must be you can remember three four  from it confidently and that would help you to   answer this question the first pattern which  comes to my mind is repository pattern why   repository pattern because if you see most  of the applications what we see around are CRUD applications that means interacting with  database insert update and delete and so on.

This repository pattern what it does is it  actually acts like an abstract layer between   the model and the data access technology you have  a model which has the business logic and then you   have data access technology like entity framework  or ADO.NET or whatever this repository pattern   can stand in between and act like a mediator and  in this repository pattern you can put you can   centralize I will say common code of data access. And with that it will help you to make it more maintainable more testable more modular and so on  first pattern which comes to my mind is repository   pattern the second pattern which goes hands in  glove with repository pattern is unit of work   repository pattern acts like a mediator and unit  of work actually helps you to manage transactions   between the repository pattern object for  example let us say you have customer and   customer has addresses you would like to say  that ok if the customer if all the addresses

Gets inserted the customer will get inserted in  other words if there is a failure in inserting   of the customer or the address everything has to  be revert back either all the customer all the   address get persisted or everything rolls back for  such kind of a thing unit of work is used inside   repository pattern actually that is there the  third pattern which comes to my mind is iterator   pattern we all do for each loop iterator pattern  what it does it is helps you to iterate over an Aggregate object sequentially without exposing  the underlying representation at the back end   you don’t know you are iterating over a  list, you are iterating over a collection,   you are iterating over a dictionary that’s  what iterator pattern does and one very   important point when you’re discussing about  iterator pattern please note in .NET and also   in Java I enumerator and I enumerable is  already there to implement iterator pattern

We don’t really have to go ahead and write a  wrapper class above it in the interview if you   can just say that you are using I enumerable and  I enumerator that itself is a implementation of   an iterator pattern the fourth pattern which comes  to my mind is factory pattern creational pattern   wherein the object creation is centralized  and the instance of the creation goes to the   derived classes this is again the fourth one the  fifth one which comes to my mind is specifically when you have incompatible interfaces. Adapter pattern specially around third   party component you have two classes and both  the classes have incompatible interfaces and   if you want to make them compatible that’s where  adapter pattern comes into picture specifically   in case of a third party a third party components  those methods you can’t change of the third party   and then you have your own classes internally  and the methods are not compatible with each

other then you put an adapter in between  and you make the interfaces compatible.  The sixth one is decorator pattern you have  an object and you want to add a behaviour   dynamically for example let us say you have an  validator object and it is doing just required   check and you want to say ok now I want to go and  do a null check also or also I want to go and do   a range number check you can add a behaviour and  remove a behaviour dynamically the seventh one is command pattern with CQRS is coming into picture  we will talk about CQRS in the later videos.  If you look at CQRS this command pattern the base  of CQRS is command pattern specifically if you are   doing MVVM also there also you will see I command  whenever you see I command it is one of the sings   saying that implement command pattern in command  pattern what happens is you treat a command as a   class or object for example till now you must  be thinking that ok what can be an object an

object can be a person it can be a car it can be a  printer it can be a customer it can be a supplier   But if I say that command can be create,  command can be update, command can be fire,   command can be throw a bomb at that time you  treat for such kind of scenario a command as   a class this is the command pattern you will find  heavy use in CQRS faced pattern again I find this   very useful for example at the back end you have  lot of things let’s say you are doing accounting

In case of an accounting you do a debit you do a  credit you do a voucher of posting but you want   to represent this system in a very simplified  way through a web API or must be through a   rest service or through a WCF or something that’s  where facade pattern comes into use it represents   and subsystem in a simplified way ninth one  is composite composite means where you have   object composed of each other for example let  us say you have a square a square has a circle A circle has a square or another example where I  use composite pattern is menu a menu has a submenu   a submenu again has a menu a composite pattern  then tenth which is very much I feel I have been   using a lot is the template pattern or template  method in template method what happens is the   steps are fixed like extraction transformation  and loading the steps are fixed but the   individual steps can be overridden in the child  classes the steps of the algorithms are fixed

But the subclass can go and override the  individual algorithm of the steps there   are the 10 patterns which I can think about and  remember I have said my patterns cannot be your   patterns I will be having two three videos  separate videos dedicated to each one of   these pattern but for now in this first video  I really don’t want to go in depth into each   one of these patterns because we have to see  the code we have to understand it see until You don’t see the code you won’t be able to speak  in the interview please understand it either you   can go and you can see my design pattern  videos there is a design pattern lengthy,   lengthy lecture of design pattern with a project  you can see that if not what I will be doing is in   a second lecture of the third chapter three  four chapters I will dedicate to these 10   patterns at least that you are able to answer in  a more confident way but for now you can choose

Your three or four remember as I have said if  you just look at your project I am very sure   you must be using repository pattern I am  very sure you must be doing a for each loop   iterator pattern is almost there I am very very  sure that you must be exposing a web API where   you don’t know you have used facade but you are  exposing the subsystem in a simplified way I am   sure that you must be creating a menu and submenu  where something is contained inside each other

Go and see your project I am sure that  you will find many of these patterns   you have implemented unknowingly and if  you speak that in that interview also it   will send a different level of confidence  now before I move to question number six  I would like to ask all our developer friends  out here for this question which is flashed on   the screen for this question which is flashed on  the screen how many how many how many of you guys

have answered singleton pattern I can see the  smile on your face if you are smiling out there   yes I answer all the singleton pattern then please  put a smiley down below in the YouTube comments   but here it is quickly about singleton pattern  not only know this pattern is favourite between   the in between the candidates while answering  the question but even the interviewers love it  With all respect for this pattern the next coming  up four or five questions are on singleton pattern let us get start it singleton pattern helps  to create a single instance of an object if   you want to create a single instance and if you  want that single instance to be shared across   your application while it is running singleton  pattern is useful now there are some use cases   of singleton pattern first one is which I have  been suing in my project is for cashing purpose  For example now let us say you have country  master you have state masters you have currency

masters then what you can do is that you can  create one single object of it one single   collection of it and use the same collection  again and again and you don’t have to make a   trip to SQL server or to your RDBMS again and  again second use of singleton pattern which I   have seen is for common data sharing for example  you have a common theme which you want to share  When your application is running you have  some configuration data which you want to share when the application is running  then singleton pattern again is useful   when such kind of question comes up it is  very very essential to show your knowledge   of to show your authority of don’t just  answer in one liner private constructor   and static keyword try to stand out  from the crowd here it is at least  I feel there are five or six important steps  which you should be mentioning when you are

talking about singleton pattern here it is step  one the first thing is I think we should have one   separate rapper class for example in this case we  are trying to load the country master for cashing   you can see there is a list of countries  you can have list of states you can have   list of currencies whatever are those singleton  objects they will be wrapped inside a separate  Class called as singleton that is the first  thing and second the access to these objects will be provided from a instance within that  mean that this singleton class instance will   be created inside the class itself this is called  as a whole part relationship you can see here this   is a singleton class and the instance is created  internally any access to the countries collection   etc. will happen through the instance that’s the  first thing I think we which you should talk about  That there should be a separate singleton class  the second one is when you talk about singleton

multiple threads can access it can be accessed  from multiple places definitely there should be   a threads safety for threads safety you can see we  have created a lock object and every time we load   an instance or every time we go ahead and load  an asset like a countries or state whatever it   is we always go and lock that object we can see  this is the second thing which should come out  That threads safety should be taken into account  by using lock by using mute x whatever way you think is good the third one is this singleton  class nobody should be able to create an instance   of it that’s why you can see that there is a  private constructor inside it this is third   thing the fourth thing is that should be lazy  loading, lazy loading or eager loading you   should have control over the loading you can see  here whenever I make a call to the get countries  The first check I do is that is the countries  collection null if the countries collection in

null then only go and load it or else don’t go  and load it again and again this is again one   more important thing out here lazy loading the  last one which I feel is very important and this   is where your knowledge will show off is that  should be a double null check why a double null   check for example you can see out here we are  using the lock keyword if somebody makes a call   to the get countries we don’t want to lock this Again and again and again remember that lock actually needs a lot of resources to acquire  a lock or to release a lock you need a lot   of resources out here this lock keyword should  not be executed unnecessarily we can see here   there is a one more null check here saying  that if the countries is null then only go   and lock it or else you don’t have to go inside  this if condition I think at least when you are   speaking in the interview three or four things Whole part relationship you are going through

a root class second one you should take care of  multi-threading thread safety locking you should   have a provision of doing lazy loading and also  if you can talk about performance that is great   when you answer in such a way in depth this is  where the interviewer connects to you let us go   ahead and run this program as well because my  goal here is to not only just make you pass in   the interview but also to give you knowledge And definitely both of them going to hand in hand when you see a demo when you understand a  concept you are in a better position to argue   in the interview you are in a better position to  handle the cross questions first thing we should   not be able to create the object of the singleton  class because the constructor is private you can   see that I am getting an error out here that it  is inaccessible due to the protection level the   second thing you can see here in line number 12  here is that we are using that singleton class

Which is now the root to first get access  of the instance once we have access of the   single instance to that single instance now  we can go ahead and say ok get me countries   get me the hit counter or get me states get me  currency and so on let us go ahead and run this   and let us see how it looks like first thing  is you will get the instance you will get the   access of the instance the root instance the  single instance and then you can go ahead and get the access of the resources And second thing  whenever you are getting access of the instance   remember the pattern which is followed out here  throughout is the first thing everything is lazy   loaded until you don’t call the Instance the  instance the singleton is not initialized see   here first thing we can see until in this first  call now the instance is getting initialized  Second you can see we have taken care of threading  all that is again there also this first null check

is for the performance why didn’t it go inside  looks like the instance was already created how   was it created why was the instance created  let me rerun the program again I don’t know   why it did not go inside that if condition  let me I think this is exe was running out   here let us go ahead and run this again strange There it is it goes inside it and if the instance   is null there that’s it I think the instance was  already running and that’s why that singleton down

object was created first thing it goes and locks  the object checks this is the first time we are   doing it lazy loading and gives you back the  instance once you have the instance with you   now you can go and say ok get me countries get me  states and the best part here is again the same   kind of structure same kind of pattern here First go ahead and check if the countries is   loaded if it is null then only go and lock the  object and then yes again and again check you if the countries is null remember this double  check is because in between somebody can call   get countries that’s why double check  is there and then again initialize the   countries now this is lazy loading and there  it is if I go and again say get countries you   can see the countries collection is out here  if I again go and see get countries out here

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent