The reason why the senior developer knew how to handle this problem, even though he never had experience in Angular, is because he knew his design patterns Namely he knew how dependency injection works (it’s used in Spring) Dependency injection isn’t an Angular pattern, rather its own design pattern, and parts of it usually go with it.
I assume the senior developer knew of the general concepts of your problem, knew some basics of how Angular was designed (not necessarily how it works) and knew of the general approach of what to do.
Obviously it takes experience to get there and know these things, but this is where fundamentals come in. If you were stuck on this problem, but had no idea how Angular’s dependency Injection system works, or that the
InjectionToken class existed you are going to end up digging into the problem without this sort of knowledge.
So now you are probably asking “Yea so how to I gain that knowledge and experience?” Well there’s 2 things.
- Find out what you don’t know
- Learn what you don’t know
Now that might sound confusing at first, but let me break it down. First there are things that are unknown unknowns things you don’t know that you don’t know, you want to limit these by seeking out knowledge to know you don’t know it. For example, in the above case you probably didn’t know the inner workings or ideas around how DI works in Angular, but once you realized “Hey I might not know WTF is going on with this concept” you’d know you didn’t know essentially, which brings in the second concept. Second there are known unknowns, like you knew you didn’t know how to fix this issue. Now its tough to figure out this issue, but it’s even more tough if your missing part of the key concepts around this issue (how the DI system works for example).
Finally there are the obvious known knowns, which are the easiest, its what you already know and can “lean on”. I assume you understand how OOP works, but you might now be 100% on DI.
So this all brings me back to the two points above. Its one thing to expand your horizons just enough and learn just enough to understand how much you actually do understand. I can talk about what the Gang of Four and the concepts built around an injection token, but without knowing about this book or the concept of design patterns in general you wouldn’t even know you were missing out on this possible experience.
Finally, even if you read the classic Design patterns book you might not even figure out this issue. (It doesn’t actually even go into Dependency Injection haha, since its a “newer” concept) and that’s where raw experience comes in. The senior obviously knew how to deal with the issue from his own experience. You can’t replace that, you can only realize your lacking it
So take this as a lesson of what can be, and a reason to continue expanding your knowledge even if you don’t need to. You wont know when you’ll need it