Object oriented execution

Consider the following source fragments:

Fragment # 1

  StoredProcedure sp = new StoredProcedure( "PROC_NAME", getConnection() );
  sp.putParameter( "ID", getId() );
  sp.execute();

Fragment # 2

  StoredProcedure sp = new StoredProcedure( "PROC_NAME" );
  sp.setConnection( getConnection() );
  sp.putParameter( "ID", getId() );
  sp.execute();

Fragment # 3

  StoredProcedure sp = new StoredProcedure( "PROC_NAME" );
  sp.putParameter( "ID", getId() );
  sp.execute( getConnection() );

Q: Which fragment is the most object oriented and why?

Q: What are the pros and cons of each fragment?

+3
source share
2 answers

My opinion: no one and they are all at the same time.

All fragments show a method with a name action. Part of the design of OO as a whole is that each method does only one thing, and the name of the method reflects this; actionas the name of the method does not reflect and can be used as a title for something. Considering what the thing actually does, this method should apparently be called something like executeProcName.

OO , . , getters - , , OO , jball . , , # 3 / ( ) # 2, .

, , , .

+2

, .

, , . , getConnection, ?

p = new Person("Joe", "Smith");

,

p = new Person();
p.setFirstName("Joe");
p.setLastName("Smith");

, .

0

Source: https://habr.com/ru/post/1725307/


All Articles