DR00ME Posted March 7, 2004 Posted March 7, 2004 (edited) I got class1 and class2....there is one sub program inside the class2... the program is using class1 public shared variables... there are many variables the class2 sub program is using from class1... I dont want to use the class1 variables like: class1.this, class1.that ..I would like to find a better solution.... if i put 'inherits class1' everything works.... but the problem is I dont want to inherit the whole damn class1 and its FORM... so is there a simpler way to do it like inheriting a part of the class ? Edited March 8, 2004 by DR00ME Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
Moderators Robby Posted March 8, 2004 Moderators Posted March 8, 2004 Would it not be better to take the guts out of class1 and place it in it's own class and not have the form stuff in there. Then you can inherit it. Otherwise it just sounds like a bunch of functions. Quote Visit...Bassic Software
DR00ME Posted March 8, 2004 Author Posted March 8, 2004 so lets say form class would be class3.... so class2 inherits class1...and class1 inherits class3.... BUT does this mean that class2 inherits class3 because class1 inherited class3....? I mean if 2 classes inherit one(the same one).... does it mean the 2 classes inherit automatically each other too? do they have a connection ? Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
Administrators PlausiblyDamp Posted March 8, 2004 Administrators Posted March 8, 2004 so lets say form class would be class3.... so class2 inherits class1...and class1 inherits class3.... BUT does this mean that class2 inherits class3 because class1 inherited class3....? I mean if 2 classes inherit one(the same one).... does it mean the 2 classes inherit automatically each other too? do they have a connection ? if class2 inherits class1 and class1 inherits class3 then yes - class2 implicitly inherits class3. That is what inheritance is all about. I think Robby was suggesting you look at your object model again (i.e. what classes contain what functionality and where is it needed). If the class contains some code you need to inherit from move that into a separate class and inherit that. i.e. If class1 contains some stuff you need to inherit move those things into a separate class (class4 for example). Now make your existing class1 inherit from class4 and make your other class (class2 or class3 - not sure which in your case) also inherit from class4. Also I hope the class names are just here as an example and not the real names you are using :-\ Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
DR00ME Posted March 8, 2004 Author Posted March 8, 2004 lol, I wish it would be that simple :D I know what robby means but I cant separate anything from my main class (AIvision).... Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
Moderators Robby Posted March 8, 2004 Moderators Posted March 8, 2004 Maybe its best you outline (to us) what each class is handling, an object model if you will. Quote Visit...Bassic Software
Joe Mamma Posted March 8, 2004 Posted March 8, 2004 I got class1 and class2....there is one sub program inside the class2... the program is using class1 public shared variables... there are many variables the class2 sub program is using from class1... I dont want to use the class1 variables like: class1.this' date=' class1.that ..I would like to find a better solution.... if i put 'inherits class1' everything works.... but the problem is I dont want to inherit the whole damn class1 and its FORM... so is there a simpler way to do it like inheriting a part of the class ?[/quote'] I dont know if this directly addresses your issue but I have a feeling applying some basic 'rules' of OOP might give you ideas. 1. Attributes of classes to be visible outside the immediate scope of a class and instance of that class are properties of that class and should be treated accordingly. It is poor style for a child class to directly access variables of the parent class. If you are tempted to access public instance variables from child classes, consider publishing them via virtual methods and properties. C# Example 1. NOTE: no claims made as to having all syntactical elements properly applied but the concept is sound public class MyClass { string classString = "MyClass"; protected virtual string GetClassString () { return classString; } public string ClassString { get { return GetClassString(); } } } public class MyClassChild: MyClass { MyClassChild(): base() { classString += " wrapped in MyClassChild"; } protected override string GetClassString () { return "Accessor Override: " + base.GetClassString(); } }Values for ClassString property on instances of type - MyClass: "MyClass" MyClassChild: "Accessor Override: MyClass wrapped in MyClassChild" 2. Program to Interfaces not to Classes. On doing analysis of the problem domain, discern the sets of methods that can be grouped together as services and declare them as Interfaces. Bear in mind that interfaces can be a) combined and inherited and b) used as casting qualifiers: C# Example 2.a. NOTE: no claims made as to having all syntactical elements properly applied but the concept is sound public interface IMethodSet1 { void Proc1(); string StringFunc1(); } public interface IMethodSet2 { void Proc2(); } public interface IMethodSet3: IMethodSet1 { void Proc3(); } public class MyClass:IMethodSet1 { public void Proc1() { //enter some code here } public string StringFunc1() { //Enter a string function body here } } public class MyClass2:IMethodSet1, IMethodSet2 { public void Proc1() { //enter some code here } public string StringFunc1() { //Enter a string function body here } public void Proc2(); { //enter some other code here } } public class MyClass3:IMethodSet3 { public void Proc1() { //enter some code here } public string StringFunc1() { //Enter a string function body here } public void Proc3(); { //enter some other code here } } C# Example 2.b. NOTE: no claims made as to having all syntactical elements properly applied but the concept is sound public class ClassProcessor() { public static void MyClassProcessor(IMethodSet1 obj1) { IMethodSet2 obj2 = obj1 as IMethodSet2; if (obj2 != null) obj2.Proc2(); IMethodSet3 obj3 = obj1 as IMethodSet3; if (obj3 != null) obj3.Proc3(); obj1.Proc1(); } } I don't know if this helps but given it sounds like you want to present various property subsets in a particular class hierarchy, this might lead you towards a more managable abstraction. Damn, I'm tired! Joe Mamma Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
DR00ME Posted March 8, 2004 Author Posted March 8, 2004 Im sure you have nice thoughts but it is a bit confusing for me because it is in c sharp format... :) thx anyway ( I know it is basically same as vb.net but to me it is a bit confusing ) and I havnt really used child classes at all... Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
Joe Mamma Posted March 8, 2004 Posted March 8, 2004 Im sure you have nice thoughts but it is a bit confusing for me because it is in c sharp format... :) thx anyway ( I know it is basically same as vb.net but to me it is a bit confusing ) and I havnt really used child classes at all... [self editted comment] :cool: I am trying to ICQ you. Have I told ya lately that I love ya!!! Joe Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
DR00ME Posted March 8, 2004 Author Posted March 8, 2004 lol, I think I pressed some wrong buttons and I lost the message... Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.