It can feel that way, but once it clicks, it really clicks. Even for simple projects what you may lose in time actually implementing OOP as opposed to functional you gain back in modularity and versatility.Toma said:Its seems like a lot is... I wouldnt say an unneccessary burden, but I tend to fall back to use ways NOT OOP even when trying to exercise OOP. Somewhere on this page I wrote that I used static methods to do stuff in my class and people just told me that with that I was basically undoing what OOP is for. Sigh.
Anyway, what the people were saying about it, already helped a great deal. Now I only need to concentrate on trying to use OOP concepts, but its hard if you programmed a while before without using OOP.
<?php
require("page.inc");
$homepage = new Page();
$homepage->content ="<h2>Blah Blah Title</h2>
<p>More Blah Blah...</p>
<p>Even More Blah Blah...</p>";
$homepage->Display();
?>
Team[] TeamArray = new Team[TeamCount];
TeamArray[counter] = new Team(elem);
List<string> TeamListe = new List<string>();
TeamListe[counter] = new Team(elem);
deadbeef said:Toma,
Do this:
List.Add(new Thing())
List<string> TeamListe = new List<string>();
TeamListe.Add(new Team(elem));
Crap, I completely missed that one.Toma said:If I do that:
Code:List<string> TeamListe = new List<string>(); TeamListe.Add(new Team(elem));
I get the same error (Cannot implicitly convert type 'soccer_table.Team' to 'string') plus a new one : "The best overloaded method match for 'System.Collections.Generic.List<string>.Add(string)' has some invalid arguments"
Edit: I am stupid, I need to change "List<string>" to List<whatever I am adding> right? But what am I adding? Its not a string, I know that much.
Edit2: Ha! Its an object! List<object>! HA!
Toma said:Edit: I am stupid, I need to change "List<string>" to List<whatever I am adding> right? But what am I adding? Its not a string, I know that much.
Edit2: Ha! Its an object! List<object>! HA!
deadbeef said:Crap, I completely missed that one.
Margalis said:It's a Team. You are adding instances of the "Team" class no?
Team[] TeamArray = new Team[TeamCount];
TeamArray[counter] = new Team(elem);
The_Technomancer said:I'm still getting used to Java, and to a lesser extent some OO stuff in general. The first command makes an array of Team, thats obvious. The second line replaces the Team at "counter" with a new Team who's constructor is fed "elem"?Code:Team[] TeamArray = new Team[TeamCount]; TeamArray[counter] = new Team(elem);
Its just a bit weird for me because I'm used to "new" being used for memory allocation, but by the time of the second line the memory for the entire array already exists?
...and I don't know if I'm making any sense.
Yeah, I just don't really see why you have to use "new" in the second line when you're overwriting an already existing element, but it could be that I'm just thinking about "new" the wrong way.Toma said:Yup, you cant directly change the sizes of arrays in c# as far as i understand. So I read out the count of items I have and created an array with "TeamCount" as the complete end size for the array which I am then filling in the second line.
(Hope I am not too wrong, beginner here.)
The_Technomancer said:Yeah, I just don't really see why you have to use "new" in the second line when you're overwriting an already existing element, but it could be that I'm just thinking about "new" the wrong way.
...I...think so, yeah, I'm really getting hung up on how I'm used to "new" working in a different context, but it makes sense now.Toma said:Because I am creating a new instance of the object "Team", which (creating new instances I mean) always uses the "new" operator, instead of just replacing the array with a string or number. Hope that made sense
If you'd use a string to replace the content it would be just:
TeamArray[counter]="lala";
You first allocate memory for an array of pointers, but the pointers themselves only contain values that are basically memory addresses. You need to then allocate memory for whatever it is that is being referenced by the pointers unless you want them to be null references (or you could point them at some existing object).The_Technomancer said:I'm still getting used to Java, and to a lesser extent some OO stuff in general. The first command makes an array of Team, thats obvious. The second line replaces the Team at "counter" with a new Team who's constructor is fed "elem"?Code:Team[] TeamArray = new Team[TeamCount]; TeamArray[counter] = new Team(elem);
Its just a bit weird for me because I'm used to "new" being used for memory allocation, but by the time of the second line the memory for the entire array already exists?
...and I don't know if I'm making any sense.
Yeah, but all that should be handled by the first line, no?Lance Bone Path said:You first allocate memory for an array of pointers, but the pointers themselves only contain values that are basically memory addresses. You need to then allocate memory for whatever it is that is being referenced by the pointers unless you want them to be null references (or you could point them at some existing object).
The first line just creates enough space for an array of values that contain addresses. The actual minimum required memory for an array that contains your objects would be n * <memory address value> size + n * <array object> size, but you've only allocated n * <memory address value> size with the first line (where n equals TeamCount).The_Technomancer said:Yeah, but all that should be handled by the first line, no?
Using the constructor in the second line to overwrite one of the elements of the array with a new object of the same class shouldn't take any more memory, does it?
Oh, really? So you have to actually construct each object in the array separately? I would have assumed that it would actually make that many objects using the default constructor.Lance Bone Path said:The first line just creates enough space for an array of values that contain addresses. The actual minimum required memory for an array that contains your objects would be n * <memory address value> size + n * <array object> size, but you've only allocated n * <memory address value> size with the first line.
The next line is allocating memory for an object that your pointer (TeamArray[counter]) will reference.
I have to say I didn't look that carefully at the original post. I assumed it was java (which doesn't have a default constructor).The_Technomancer said:Oh, really? So you have to actually construct each object in the array separately? I would have assumed that it would actually make that many objects using the default constructor.
I'm still trying to make sense of this from a C++ background with very little experience in Java, but there's no default constructor?Lance Bone Path said:I have to say I didn't look that carefully at the original post. I assumed it was java (which doesn't have a default constructor).
The_Technomancer said:I'm still trying to make sense of this from a C++ background with very little experience in Java, but there's no default constructor?
*shrug* learn something new every day.
Yeah, it makes more sense the more I think about it, from an efficiency perspective.mike23 said:There is a parameterless constructor in Java, but there is no guarantee that a class would have it.
Language designers usually try to follow the "Principle of least astonishment". Filling the array with default constructed classes would astonish me. Especially if my class didn't have a default constructor.
int get(int key) {
int hash = (key % TABLE_SIZE);
while (table[hash] != NULL && table[hash]->getKey() != key)
hash = (hash + 1) % TABLE_SIZE;
if (table[hash] == NULL)
return -1;
else
return table[hash]->getValue();
table[hash] != NULL
The_Technomancer said:So then won't it return -1 if the keys mismatch but the entry is NULL?
Form Form2 = new Form();
Form2.TextBox1("aaaa");
Kalnos said:Form.text just sets what the form is called if I remember right (in the top left), I don't think that's what you're looking for. If you're wanting text to appear inside the form you will need to use a textbox or a label.
I may be interpreting what you're doing wrong though.
Form.text is usually just set through the 'properties' window and put into the 'designer' code automatically by the compiler.
Different Class
Form1.InputString("aaaa")
Form1
public void InputString(string Input)
{
TextBox1(Input);
}
deadbeef said:Can you please clarify what you are trying to do?
public void UpdateLeague(string Team, int Points, int GoalsPlus, int GoalsMinus)
{
}
Form1.UpdateLeague("lala",6,6,4);
Kalnos said:Toma, you're calling Form1.Method(string) (I.E. the class, not the instance) version of that method rather than the actual instance of the form. It's expecting a static method because that's the only way you could do that.
You need to reference the actual form, not the class.
Toma said:Ah, but the instance of that Form was created on startup, how I find out how this exact instance is called?
Toma said:Sorry if I cant explain it well enough.
I have a Form open, and want to access methods of that window in a different class.
Form1.cs(the open window):
Code:public void UpdateLeague(string Team, int Points, int GoalsPlus, int GoalsMinus) { }
...which i want to access from a different class
League.cs:
Code:Form1.UpdateLeague("lala",6,6,4);
http://i55.tinypic.com/iyfup5.jpg
Sorry, if I dont use the correct terms for something =/
LeagueEditor editor = new LeagueEditor()
public List<string> getTeams()
{
// Good stuff goes here
}
// Inside create league click event
LeagueEditor editor = new LeagueEditor();
if(editor.ShowDialog() == DialogResult.OK)
{
// User interacted with league editor and clicked Done.
// This means he/she is done editing a league. Time to harvest.
List<string> teams = editor.getTeams();
// Fill LeagueSimulation TextBox with teams however you want.
}
Kalnos said:Let me ask a few things:
League_Simulation = Form1.
League_Input = Form 2. (created when pressing Create League?).
EDIT: Fuck all of that, I'm even more retarded than I thought.
Just pass a string by reference into Form2.
deadbeef said:stuff
Toma said:Never did that. How would that work? And what would it exactly do?
And yeah, Form 2 is created when pressing Create League.
Edit: just saw your response, thanksWill take me a while to understand and try out what you wrote.
deadbeef said:It is common practice to have an OK button that has a DialogResult of OK and a Cancel button that has (surprise) a DialogResult of Cancel.
By treating LeagueEditor like a Dialog, it becomes "modal", which for your user means that they can't interact with the rest of your application until they get done with editing the list of teams. You get this behavior by using the ShowDialog method.
If you want the user to be able to have both the League Editor and the League Simulation windows open at the same time, then you need to use the Show method. But that will introduce additional problems for you that I don't think you really need to deal with at this time.
class
{
void Add(int x)
{
x = x + 1;
}
}
int Main()
{
int x = 3;
Class c = new Class();
c.Add(x);
Console.WriteLine(x);
c.Add([B]ref[/B] x);
Console.WriteLine(x)
}
Printout:
3
4
Kalnos said:Stuff.