Hi every one, the book suggested that I should come here if I struggle so here I am!
Firstly I am already a coder at
VB and Oracle SQL.
I understand and use Object orientated programming but I never formally picked it up, I just learned as I went.
The idea is to pick up C# but at the same time formalise my knowledge of OOP theory; to learn what I am actually doing instead of just knowing why I should.
I know im head over heels and backward (know and LOVE linq, but unsure of real OOP theory?) but its just the way my knowledge has developed.
So, hope some one can help!
under chapter 2, understanding objects, the author states that a statement should be written as 'clsPerson myFriend' then 'myFriend = new clsPerson();'.
so step by step with the authors code.
Firstly the author created a pointer called 'myFriend' which will point to an instance of the class clsPerson.
Now, what confuses is that in all programming languages I have used thus far, you follow the syntax 'varName var Type', this is what im used to.
e.g.
Dim myString as string
myString varchar2(255)
etc etc etc.
Its probably my inexperience with C#, but why is it swapped in this case? why is the varType first, then the varName second? Are we saying 'create a generic pointer, which will point to a clsPerson type? Therefore would 'string myString' -in theory- be valid as its a pointer?
I am struggling to wrap my head around this requirement.
Websites suggest writing the line combined as 'clsPerson myFriend = new clsPerson' but tht is no clearer even though I know it does the same thing.
by my understanding, when I create a 'myString varchar(255)' I am saying 'reserve a block of ram, the size and type of a char char, 256 long. when ever I refer to 'myString' I want you to refer to that varchar memory'.
by that same logic, in the above line I am saying 'a type of clsPerson, called myFriend, reserve memory for a clsPerson' and its that which breaks me down .
I hope I make sense.
P.s. The cookie cutter analogy, whilst good is maybe confusing me a little as its saying, to me, make a copy of the cookie cutter, then copy it again, then use the copy to punch out a space of ram and call it my friend. why make a copy of a copy?
Update:
Okay thinking about it a lot more, im starting to get a handle on it a little more now.
Ive gone about it the wrong way round. When you use the 'new' keyword and declare a class, it creates the memory space, but throws back a memory location. without some where to store the memory location it will fail. So we give it a place to store the memory location, myFriend. therefore we have to create that pointer first, which we do via 'clsPerson myFriend'.
The end result is that calling 'myFriend' calls the memory location created by the 'new' keyword earlier.
Still don't understand why the varType comes before the varName however or is this combination just the C# syntax for a pointer?