Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Feb 15th, 2006, 1:21 AM   #1
Darkhack
Hobbyist Programmer
 
Darkhack's Avatar
 
Join Date: Dec 2005
Location: Kansas City
Posts: 105
Rep Power: 3 Darkhack is on a distinguished road
Send a message via AIM to Darkhack
OOP Theory - MI of Objects

You'll probebly see me making a million threads like this, lol. I love talking theory. I dont have a lot of expierence with seeing other peoples code so I don't know how things are done by others. Anyways, I was wondering if this theory is acceptable to most programmers. Is it good/bad practice to create all of your objects and then allow them to be used by every other object? I know that sounds confusing. Look below for an example... As you can see I define my objects in advanced and then inherit all of my classes on the main one. That way I can call all of my objects from inside the objects themselves. I actually found this to be pretty easy in some cases. Although I question whether it is acceptable among other programmers. Although this is good in theory, it may prove a little difficult to manipulate it if you had more than instance of a class because of the issues involving which object to manipulate, but if you are careful, I am sure you could work around it. Although if you are only using one instance of a class, it certainly saves you the time of having to pass the objects as parameters and then return them.

// MAIN
public class MainClass
{
	public SubClass obj1;
	public AnotherClass obj2;

	public static void Main()
	{
		obj1 = new Subclass();
		obj2 = new AnotherClass();
		
		obj1.Display();  // <-- basically the same as obj2.Output();
	}
}

// SubClass + AnotherClass
public class SubClass : MainClass
{
	 public void Display()
	 {
		 obj2.Output();
	 }
}

public class AnotherClass : MainClass
{
	public void Output()
	{
		Console.WriteLine("I'm AnotherClass being called from SubClass!!!");
	}
}
Darkhack is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:09 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC