+ 2

OOP Question I Couldn't Solve in an Interview

Ladies and gentlemen, last week I was in a technical interview with few other people where we were trying to solve 4 questions given to us. I managed to solve 3 questions in 10 minutes (45 minutes total) but there was this question I couldn't do anything on and this is making me so unhappy and disappointed. Because I was feeling like I was good at Object Oriented Principles. I felt like broken after the interview just because of this question and I know it is fundamental... So the question is this: There are two classes "Class X" and "Class Y". As you see in the code, Class X executes "a->x->b" and Class Y executes "a->y->b". "a" and "b" is being executed twice and this is a bad practice. How can we rearrange the classes so that the execution order is preserved, a and b executed once and the classes only execute "x" and "y"? (There are no specific rules, you can create other classes, methods etc. as long as the goal is achieved) Class X { ... void foo() { a x b } ... } Class Y { ... void foo() { a y b } ... }

22nd Oct 2017, 8:59 AM
Mert Açıkportalı
Mert Açıkportalı - avatar
2 Answers
+ 3
Yeah, I think this is one of the viable answers. I'm open for more tho 😅
22nd Oct 2017, 10:50 AM
Mert Açıkportalı
Mert Açıkportalı - avatar