0

Say for instance i have the following class:

    class SuperModel
{
    private OracleProvider database;
    private SqlTemplates template;
    public SuperModel()
    {
        this.database = new OracleProvider();
        this.template = new SqlTemplates(database);
    }

    protected SqlTemplates getTemplate()
    {
        return this.template;
    }
}

Now i have the following class extending the above:

    class Henvendelser : SuperModel
{
    public Henvendelser()
    {

    }

    public ArrayList getQueue(DateTime start, DateTime end)
    {
        String sql =
                "SELECT                                                                     " +
                "   TIDSPUNKT,                                                              " +
                "   NVL(QUEUE,' ') AS QUEUE,                                                " +
                "   NVL(SUM(ANTAL_KALD),0) AS CALLS,                                        " +
                "   NVL(SUM(ANTAL_BESVARET),0) AS ANSWERED_CALLS,                           " +
                "   NVL(SUM(BESVARET_25_SEK),0) AS ANSWERED_CALLS_25_SEC,                   " +
                "   NVL(SUM(INTERN_KALD),0) AS INTERNAL_CALLS                               " +
                "FROM                                                                       " +
                "   KS_DRIFT.PERO_NKM_KØ_OVERSIGT                                           " +
                "WHERE                                                                      " +
                "   TIDSPUNKT >= '" + start+ "' AND                                         " +
                "   TIDSPUNKT <= '" + end + "' AND                                          " +
                "   TO_CHAR(TIDSPUNKT,'DY') NOT IN ('AB')                                   " +
                "GROUP BY                                                                   " +
                "   QUEUE                                                                   " +
                "ORDER BY                                                                   " +
                "   TIDSPUNKT                                                               ";

        ArrayList result = this.getTemplate().template(sql, SqlTemplates.READ_FROM_QUERY);
        return result;
   }
}

is the SuperModel's constructor called automaticly or do i have to do something in order to make sure it is called?

Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364

1 Answers1

6

In your particular code it is called implicitly. To explicitly call it you will need to use base keyword.

See: Using Constructors C#

In a derived class, if a base-class constructor is not called explicitly by using the base keyword, the default constructor, if there is one, is called implicitly.

So your constructor in derived class:

public Henvendelser()

is equal to

public Henvendelser() :base()

Other little observation in your code:

  1. Use List<T> instead of ArrayList
  2. Use Parameters with your query instead of string concatenation. See Sql Injection
Habib
  • 219,104
  • 29
  • 407
  • 436
  • When will you ever need to use explicitly? – Marc Rasmussen Mar 13 '14 at 13:13
  • 1
    @MarcRasmussen, one particular case could be if there is no default (without parameter) constructor in the base class, – Habib Mar 13 '14 at 13:14
  • i am using ArrayList because im trying to make it as generic as possible and with ArrayList i dont have to specify what goes into the list? – Marc Rasmussen Mar 13 '14 at 13:18
  • @MarcRasmussen, You should see: http://stackoverflow.com/questions/2309694/arraylist-vs-list-in-c-sharp – Habib Mar 13 '14 at 13:19
  • @MarcRasmussen - ArrayList is worse if you can use List you should. If you want to "put off" knowing the type then use var – Hogan Mar 13 '14 at 16:04