Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 OOP
Index -> General Discussion
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Blade




PostPosted: Tue Nov 18, 2003 1:50 pm   Post subject: OOP

ok. is this right?

you have a class.. the class has an array of information that is created. you tell the class to add another object to your array, and all the information is stored in the class (making it less dynamic)

or

you have an array in your main program. when you want something added you use an element in the array and call the class, the class calculates what is needed and is stored in the element of the array in your main program

which is it?
Sponsor
Sponsor
Sponsor
sponsor
rizzix




PostPosted: Tue Nov 18, 2003 4:07 pm   Post subject: (No subject)

i'm not sure what ur trying to say.. anyways #2 does not seem right

and #1 appears correct.. but that does not make it less dynamic
Blade




PostPosted: Tue Nov 18, 2003 8:44 pm   Post subject: (No subject)

ok lets say you have a list of people. they have information such as a name, phone number, and address

you have a class to manage these people.

a) your class contains an array of the people with their information. you use it to create more people, delete people, and add their information
you add people by calling a procedure in your class that takes care of it..

b) in your main program, you have an array of your class, each time you add someone you use an element in your array

in turing it would loook like
people(1) -> addperson

then your element would be a new person in the array.
-----
so, the difference is, in (a) you're information is contained in the class, and (b) you're information is created by the class, but is contained in the main program... so you're class creates in individual and adds it to a main program array

i hope i explained it well enough
Catalyst




PostPosted: Tue Nov 18, 2003 9:24 pm   Post subject: (No subject)

you could always use 2 classes such as Person and ListOfPeople
rizzix




PostPosted: Wed Nov 19, 2003 12:29 am   Post subject: (No subject)

yep .. A sounds good!


but i wouldn't recommend u letting the addPerson method to create a person it self

here's what i'd thing would be a better design:
code:

class Person {
    ...
}

class PersonList {
    ...
}

some method that happens to be adding a person to the list {
    Person prsn;
   
    prsn = new Person("John", "Doe");
    plist.addPerson(prsn);

}

:: and this would be a property of a class
PersonList plsit = new PersonList();


you get the idea Smile
Blade




PostPosted: Wed Nov 19, 2003 2:59 pm   Post subject: (No subject)

awesome, i knew you guys would take my side. that was my idea. my teacher said that you use the class to create and store the information. but i said we should use a class to create people, and in turn you would have to use another class to make the list, or queue of people in my case

umm... are you unable to have more than one class in a file? like

code:
class classname1

end classname1

class classname2

end classname2

the teacher has us put our classes in another file and use unit before declaring classes..
gives an error: extraneous text at end of file
rizzix




PostPosted: Wed Nov 19, 2003 4:18 pm   Post subject: (No subject)

thats the thing about the unit in turing
it means only one class/module per file

if u omit the unit the u can have more than one..
Display posts from previous:   
   Index -> General Discussion
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: