Solved

Question object object creation

Posted on 2006-10-25
1
193 Views
Last Modified: 2010-04-16
I have a couple of classes listed below



public class House
{
   public House()
   {

   }

  // attributes
  int houseID = 0;
            

  // Get HouseIDID
  public int HouseID{
        get { return houseID; }
        set { houseID = value; }
  }

}

-----------------
public class HouseServices
{

      public static House GetHouseByID(int houseID)
      {
          House result;

            // data access stuff

            result = ConvertHouseInfoDataTableToHouse(HouseInfo);
            HouseInfo = null;
          return result;
      }


      public bool UpdateHouse(House House)
      {
            bool result = true;

            // data access stuff

              return result;
      }
}




---------------------------------
code calling these classes:
---------------------------------
#1
House myHouse;
myHouse = HouseServices.GetHouseByID(3);

myHouse.ID.ToString()
etc...


#2

HouseServices houseServices = new HouseServices();
houseServices.UpdateHouse(house)

---------------------------
Questions:
---------------------------
A. Why do I need to create an object for the updatehosue method for #2?

B. House myHouse. What is myHouse called? Is it a Class variable? Its not an object as it is.

C. Why dont I need to create a HouseServices object for #1?


0
Comment
Question by:tmueller18
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 500 total points
ID: 17808231
A. Why do I need to create an object for the updatehosue method for #2?

The UpdateHouse method has signature:
      public bool UpdateHouse(House House).

The method is NOT static, i.e. it means it can be called only on an instance of HouseServices class.


B. House myHouse. What is myHouse called? Is it a Class variable? Its not an object as it is.

myHouse is an instance of an object. When you write "House myHouse;" you are not creating an object, you just create a reference to an object, and this reference points to "null". You may call it null object.
So the instance of the House is sayed to be null.

The above is not 100% correct however. Just think about the "myHouse" as a some kind of a "pointer" to the object.

C. Why dont I need to create a HouseServices object for #1?

The GetHouseByIDmethod has signature:
public static House GetHouseByID(int houseID), i.e it is static, in other words it is CLASS method, not instance method and therefeore needs not an instance to be created.

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question