?
Solved

Question object object creation

Posted on 2006-10-25
1
Medium Priority
?
194 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 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