Question stuck understanding OO concepts

false74

Well-known member
Joined
Aug 4, 2010
Messages
76
Programming Experience
Beginner
Ok I am working on software to keep score of a football game.

so i have a class called FOOTBALL,
then another 3 classes/forms that inherit FOOTBALL, they control score (SCOREBOX), possession (POSSBOX), and quarter (QUARTERBOX).

the FOOTBALL class has 4 variables, "score" (array of 2 ints), "teams" (array of 2 strings), "possession" (boolean), and "quarter" (int)

after that i have another form called MAINBOX, which creates new instances of the 3 classes (SCOREBOX, POSSBOX, and QUARTERBOX) (like this: private scoring = new SCOREBOX)... however they all technically create their own FOOTBALL classes, so I cannot connect them.

forexample the POSSBOX also shows the teamnames but the SCOREBOX sets the teamneams, since they have separate FOOTBALL classes they don't talk to eachother. What is the proper way to do this?

Hope that all made sense. :D
 
inheritance is a powerful tool when you know how to use it...

Ok, first of all OOP is'nt just a trend it's a philosophy, in OOP the main objective is defining your classes and what is their purpose? Are they a unit in your world (program) or just a "screen" that displays messages (or scores..). Inheritance is not used (well unless you make a messenger class.. ) to help class' communicate with each other, but to assemble similar behaviours. It's the entry point to polymorphism (def: Generalisation to Specialisation). Basically, inheritance is the use of the power of indirection.Example:
VB.NET:
Class Person
  private string as Name
 public sub New(s as string)
 Name=s
 end sub
  public function GetName() as String
    GetName=Name
  end function
end class   
Class Secretary
inherits Person
public sub New (s as string)
MyBase.New(s)
end sub
public sub DoFingerNails()
Paint () 
end sub
end class

Dim arr(50) as person
Dim DumbBlond as Secretary=new  Secretary("Sarah Palin")
arr(0)= DumbBlond 'Because Dumblond is person she can mix with other persons

Back to your football game you need: something to do communication or to manage,hmm maybe a Game class (or GameManager class) you have score boards what does a score board do..? That's you to tell me ;)
 
Last edited:
Thank You! It makes sense now. On a side note/question, is it possible to create SCOREBOX, POSSBOX, QUARTERBOX all at the same time, so they all point to the same inherited class (FOOTBALL)? Just wondering
 
Basics of inheritance

Wow, your are mixing communication between classes with inheritance! Inheritance is regrouping behaviours togheter!Example Class A inherits from Class Z and Class B inherits from Class Z too, well when you instanciate Class A it will create it's own class Z and it wil be the same wth class B, so no they won't share the same Class Z !!. Example: You have your class Football, Football will manage the creation of your IDisplay boxes (you'll see where i'm going). Football will not inhherit from no class and no class won't inherit from it (no need for our small world which represents a football game).ex:


VB.NET:
'I'll leave you a hint for the creation of your Class Football later on !!!
Interface IDisplay
public sub Display()
end interface
'Please read on interfaces and inheritance, interfaces for language like VB is important  because VB does not support multiple inheritance but supports the implementation of multiple interfaces !!

Class DisplayBox
implements IDisplay

protected scores_(2) as string 'Because even if it's a score it could be a string....
protected teams_(2) as string

'Must be implemented because DisplayBox implementsIDisplay


overridable public sub Display () 
end sub  
        
end class

Class ScoreBox
inherits DisplayBox

overrides public sub Display() 'overrides==Polymorphism
System.Console.Write(The scores are " & teams_(0) & " =: " & scores_(0) & " and " & teams_(1) & " =: " & scores_(1) & "!")
end sub

end class

'Hint for Football class if you are not managing a division. Design pattern singleton
'If your managing a didvision then DivisionManager would be a singleton that would _ manage Manay FOOTBALL instances (games..) and a FOOTBALL would manage or create
the desired display boxes and it would have variable possesion as boolean...


I think i mentionned alot of stuff, now surf the net and buy some books....
 
Back
Top