A
Alan Kordy
I am new to OOP and C#, and I am just a beginner to learn those stuff.
Hopefully someone can give me some guidance about object design.
Let say, I want to create a class called Book. This class will have a public
method to create new book.
public class Book {
public int New (String ISBN, String BookTitle) {
...
...
}
}
My question is, can we create this method with static modifier? Like:
public class Book {
public static int New (String ISBN, String BookTitle) {
...
...
}
}
So, if we created this method with static modifier, we don't even need to
instantiate an object when we want to create a book, as we can just use the
static method. May I know which way is the correct way when we design a
class with above siatuation? What is the pros and cons?
Thanks
Hopefully someone can give me some guidance about object design.
Let say, I want to create a class called Book. This class will have a public
method to create new book.
public class Book {
public int New (String ISBN, String BookTitle) {
...
...
}
}
My question is, can we create this method with static modifier? Like:
public class Book {
public static int New (String ISBN, String BookTitle) {
...
...
}
}
So, if we created this method with static modifier, we don't even need to
instantiate an object when we want to create a book, as we can just use the
static method. May I know which way is the correct way when we design a
class with above siatuation? What is the pros and cons?
Thanks