Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Question object object creation

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

Technology Partners: 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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

610 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