Why Connection doesn't have executeQuery method

73 Views Asked by At

Why executeQuery() method isn't available in Connection Class?

If it was available we can easily call executeQuery method using Connection Object.

So can't we extend the Statement Class to Connection Class to achieve this?

1

There are 1 best solutions below

0
On BEST ANSWER

It break the Single responsibility principle

principle that states that every module or class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class.

Connection class handle connection and doesn't decide/know how to execute the query (single, batch, template...)