C
C#2y ago
fateos

❔ HeadFirst Design Pattern

So I started with this Book today. First problem starts with the Duck Project: and when he tests he makes an instance of an abstract class ???? Is this a Java thing that works but not in C#?
41 Replies
TheRanger
TheRanger2y ago
he did not make an instance of an abstract class
fateos
fateosOP2y ago
Duck mallard = new MallardDuckk
TheRanger
TheRanger2y ago
Duck is an abstract class MallardDuckk isnt
fateos
fateosOP2y ago
but how can you say Duck mallard = ?
TheRanger
TheRanger2y ago
he's making an instance of MallardDuckk, not Duck its upcasted
fateos
fateosOP2y ago
so you can make a variable of Duck but not with the new operator
TheRanger
TheRanger2y ago
yes
Pobiega
Pobiega2y ago
variable can be Duck, the instance can't. abstract just means "you cant create instances of this type"
fateos
fateosOP2y ago
oh okey so my problem is different
fateos
fateosOP2y ago
fateos
fateosOP2y ago
this is in my program.cs
TheRanger
TheRanger2y ago
what does the error message say
Pobiega
Pobiega2y ago
That should be fine, assuming your namespaces and stuff are correct.
fateos
fateosOP2y ago
fateos
fateosOP2y ago
is it because my class has the same name as my project?
TheRanger
TheRanger2y ago
dont name ur namespace and class the same name
Pobiega
Pobiega2y ago
Your type shares a name with the namespace. yes
fateos
fateosOP2y ago
so I have to find a way to refactor all namespaces in my project
Pobiega
Pobiega2y ago
thats fairly easy, just use the built-in renaming tool. Ctrl+R, R by default. set your cursor (the writing marker) on the namespace and do the shortcut
fateos
fateosOP2y ago
oh thats coolk thank you so does this replace everyything in my solution or project? and is it casesensitiv and matches the exact word?
Pobiega
Pobiega2y ago
namespaces are case sensitive
fateos
fateosOP2y ago
because I was using CTRL + H all this time yes I know but the CTRL+R,R I mean
Pobiega
Pobiega2y ago
so, thats your normal text-based search and replace the rename tool follows code references
fateos
fateosOP2y ago
for example I wanna replace foot but have other variable called football would CTRL + R, R also change the foot in football?
Pobiega
Pobiega2y ago
no its not doing it by text its doing it by the code identifier
fateos
fateosOP2y ago
by code identifier u mean if I change namespace it only looks for other namespaces and not variables or anything else
Pobiega
Pobiega2y ago
yeah, its context aware if you are changing a namespace, it only changes namespaces. but it changes them everywhere they are used, including in fully qualified type names etc
fateos
fateosOP2y ago
so for variables I shouldnt use CTRL+R,R
Pobiega
Pobiega2y ago
yes you should its context aware. it knows what it is changing its NOT a string based search and replace.
fateos
fateosOP2y ago
hmm ok so when would u use CTRL + H ?
Pobiega
Pobiega2y ago
never, for changing code search and replace is dangerous, as "foot" and "football" shows
fateos
fateosOP2y ago
ye I didnt know about CTRL+R,R so I would always go with CTRL+H and go each change one step at a time to make sure everything gets renamed correctly thankk you all I just had to put using DuckProgram; and now it works
Pobiega
Pobiega2y ago
you can set a "default namespace" in your project properties too so a new file wont get Duck by default
fateos
fateosOP2y ago
well its my fault I need a Duck class but I can call my project whatever
Pobiega
Pobiega2y ago
you could just rename the Duck class 🙂 DuckBase or something
fateos
fateosOP2y ago
it wouldnt make sense to change the Duck class it makes more sense to rename the Project
Pobiega
Pobiega2y ago
sure, but more work 🙂
fateos
fateosOP2y ago
how? CTRL R, R did it perfectly
Pobiega
Pobiega2y ago
¯\_(ツ)_/¯
fateos
fateosOP2y ago
🙂
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server