Jump to content

Recommended Posts

Posted
8 minutes ago, dasari4kntr said:

there are object initializations using NEW keyword…in the constructor..how do you deal with them..?

 powermockito.whennew() can be used to assign a mock SqlDatabase object.

Then use reflection to access the database mock.

Then verify that database is calling save.

Generally the whennew() should work within method I guess this works with in constructor too.

 

.. I may give this answer on the fly in an interview but don't know the exact trueness

Posted
13 minutes ago, dasari4kntr said:

there are object initializations using NEW keyword…in the constructor..how do you deal with them..?

Dependency injection kada bro..should not be using new in there..constructor injection cheyachu kada.. enka test ki mock pass cheyachu ctor lo

  • Upvote 1
Posted
7 minutes ago, anna_gari_maata said:

 powermockito.whennew() can be used to assign a mock SqlDatabase object.

Then use reflection to access the database mock.

Then verify that database is calling save.

Generally the whennew() should work within method I guess this works with in constructor too.

 

.. I may give this answer on the fly in an interview but don't know the exact trueness

yes...you need powermockito for that...but still your test is fragile...and your tests will be slow...

 

the same class...if i change using last SOLID principle  .. (dependency inverrsion)....this is how it looks...and its easy to write better unit test..

// Refactor to use dependency injection
class OrderService {
    private final Database database;
    private final Logger logger;

    public OrderService(Database database, Logger logger) {
        this.database = database;
        this.logger = logger;
    }
    // ... rest unchanged ...
}


 

  • Thanks 1
Posted
6 minutes ago, Abhagyudu said:

Dependency injection kada bro..should not be using new in there..constructor injection cheyachu kada.. enka test ki mock pass cheyachu ctor lo

yes.....exactly..

thats why i gave poorely written code...as example...to prove the importance of SOLID principles...

Posted
37 minutes ago, anna_gari_maata said:

Dependency injection far more easier than SOLID. ee kaalam lo Spring vacchaka kooda DI questions ante driver role ki car mechanic interview chesinattu untadi...

SOLID daka kooda evadu rayatle because most of the legacy code founders rastaru only new project aithe tappa. 

IMO ippudu vacche developers ki end-to-end and system level knowledge is more important than foundations and principles. If we want to hire a butler they don't need to know how the building pillars are made

But again it also depends on the role they're hiring

dependency inversion is SOLID principle…Dependency Injection…is the technique to implement dependency inversion…

for example…you moved to a nee project like from java to python or something else…అక్కడ నీకు.. springboot antha easy గా ఉండవు…ready గా…

i am old developer…i seen bad legacy code and using SOLID how we refactored it…thats why i always give importance to this concept…

Posted
6 hours ago, Spartan said:

frankly....interviews ki tappa...real world daily work lo does anyone even care about these anna..

SOLID, ACID... etc

vatillo unna concepts over the period experience to ostai....but desining or coding appudu I havent seen anyone bring this up and adhere to them..

unless someone wants to play Devils Advocate during the session....

@Konebhar6 @dasari4kntr @csrcsr

Microservices made lot of oops design obsolete. No one writes tons of classes anyway.

Posted
7 hours ago, dasari4kntr said:

రెండు interviews..లో ఇద్దరిని అడిగితే …ఇద్దరూ నీళ్ళు నమిలారు…

Neellu pettakapothe beer pettochuga kanisam

 

Posted
5 hours ago, dasari4kntr said:

sare.. @Spartan @Mr Mirchi...ee code ki unit test ela raastro.. cheppandi....

class OrderService {
    private final SqlDatabase database; 
    private final FileLogger logger;    

    public OrderService() {
        this.database = new SqlDatabase(); 
        this.logger = new FileLogger();    
    }

    public void processOrder(Order order) {
        try {
            database.save(order);
            logger.log("Order processed: " + order.getId());
        } catch (Exception e) {
            logger.log("Error processing order: " + e.getMessage());
        }
    }
}

 

Db lo kuda interview cheyalaaa… Adhyaksha idhi nyayamrnaaa ;)

Posted
2 minutes ago, Mr Mirchi said:

Neellu pettakapothe beer pettochuga kanisam

 

lol…can you give your contact…next time..if they can’t answer question…i will call you to serve beer…

Posted
6 hours ago, anna_gari_maata said:

Dependency injection far more easier than SOLID. ee kaalam lo Spring vacchaka kooda DI questions ante driver role ki car mechanic interview chesinattu untadi...

SOLID daka kooda evadu rayatle because most of the legacy code founders rastaru only new project aithe tappa. 

IMO ippudu vacche developers ki end-to-end and system level knowledge is more important than foundations and principles. If we want to hire a butler they don't need to know how the building pillars are made

But again it also depends on the role they're hiring

With experience, people automatically adapt SOLID principles without even knowing... These are not like inventions, someone put together the best practices based on lessons learned over time. Just like how OOP evolved from lessons learned from functional programming. 

Yes, now a days 90% coding is cookie cutter..use libraries and implement business logic. 

Unless some one is writing core reusable libraries , you don't need expert software engineering skills. 

 

Posted

“Dependency Injection” is a 25-dollar term for a 5-cent concept. That’s not to say that it’s a bad term... and it’s a good tool. But the top articles on Google focus on bells and whistles at the expense of the basic concept. I figured I should say something, well, simpler.

The Really Short Version

Dependency injection means giving an object its instance variables. Really. That’s it.
 

https://stackoverflow.com/questions/130794/what-is-dependency-injection#:~:text="Dependency Injection" is a 25,an object its instance variables.
 

DI anedi okkate solid lo use chestham emo…..its a simple concept with a complex name.

 

 

migathavi we dont usually care for example Liskov principle is taken care by compliers. Its good to know all these concepts but they are simple but not as important as tools.

  • Upvote 1
Posted
8 hours ago, Pavanonline said:

Microservices made lot of oops design obsolete. No one writes tons of classes anyway.

You mean MS frameworks like spring boot etc ? 

That's what I was saying- not many write reusable, library kind of code these days.

 

There's a section of people arguing that over engineering in the name of reusability etc doesn't hold practical value given how fast everything is changing, especially for start-ups and low- volume intranet applications.

For start-ups, once they see traction and userbase they rewrite from scratch as v2. V1 is always with off the shelf, easy to prototype frameworks which allows you to do 90% with 10% of effort. 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...