Object oriented c# [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a class called Promotion (model class). I want a promotion to have a type called Category where Category is its own model class I'm assuming where I would define all the types of categories such as fast food foot wear jewelry and so on. I'm not quite sure of how to go about this though so for example, my class called category is already a set thing but my class promotion is something where before I create it I need to set it with a category with the viable category options. thank you!

why don't you create a property called Categories of type Category in the Promotion?
enum Algorithms
{
FCFS,
SJF,
PRIORITY,
RR
}
class Process
{
public Algorithm algorithms{get;}
}
For the detailed difference please read the answer from this SO answer

Related

is it bad practice that a child class does not use all parent's elements? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 days ago.
This post was edited and submitted for review 8 days ago.
Improve this question
My question is related to inheritance it.
Let say we have a class called Animal. All animals share some behaviour like walking, pooping, hunting, etc. After few days I decided to add a Fish class that extend Animal class. But here fish swims but does not hunt or walk.
Is it OK to use only some parts of the base class? Because Fish class can still calls walk and hunt but does not execute the behaviour, I guess.
I could go around the problem where i make a function called behaviour in base class and let the child class override it.
Like this:
public class Animal
{
public virtual void behaviour() {
Console.WriteLine("//do something");
}
}
public class GoldFish : Animal
{
public override void behaviour() {
Console.WriteLine("goldfish swims");
}
}
Any suggestion on how should go about this with best practices of programming?

Searching an object in a collection via lambda and does not return true even if it exist [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
https://www.youtube.com/watch?v=K1xrlc32Tmw&list=PLJUoF2h8Z-brW94dTZ-ZIOhjFq90_lt5K&index=9
4:25 adds a new object in the lineCollection if product does not exist in lineCollection, but at 24:25 it shows duplicating orders? Did i misunderstood how it works?
https://github.com/jedjad/GitHubVS2013
Because the products in duplicate values are not same objects. They may have same names, quantity etc, but initializing a class with same values does not mean that it is the same object as the one initialized before. They are like 2 different apples with same color and size.
If you say that 2 products are same whenever the names are same, then implement IEquatable<Product> in Product class.
public bool Equals(Product other)
{
return Name == other.Name;
}

Partial class sharing same method names [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
If a partial class has the same method name but different types I will get an error right?
public partial class Employee
{
public int sum()
{
}
}
public partial class Employee
{
public string sum()
{
}
}
Yes, it does:
'Employee' already defines a member called 'sum' with the same parameter types
Partial classes are just the same as regular class, except their definition is split in two sources. They have to comply to every rule regular classes have. That includes rules concerning the uniqueness of method signatures.

Polymorphism in c# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a problem with a class that is to spawn instances containing one out of about 30 objects of different types (I call it out_out_of_many_types_of_subcontract in the code snippet below).
class supercontract
{
void supercontract (float date, one_out_of_many_types_of_subcontract subcontract)
{
stuff....
}
}
Is there any way of declaring a semi-generic variable or must I (1) resort to polymorphism between constructors or (2) casting an object as a certain type with a block of (else)if clauses?
Cheers!
I would make them all implement a single interface.
interface IContract{}
class AContract: IContract {...}
Even if the interface is empty you can limit what types could be passed to your method.

Best practices, loading model objects from database [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I've got the following model class:
public class Product
{
public int ProductID {get;set;}
public string ProductName {get;set; ]
public int ActiveOrdersCount {get;set;}
public Category[] Categories {get;set}
//etc...
}
When I load a product from the database, I load all the properties and maybe lazy-load the categories.
Does it make more sense to load all the properties of the object or partial etc?
It depends on how the objects will be accessed at run time. If you want to immediately access the categories collection for all of the products in a collection, then lazy loading will be very chatty.
On the other end of the spectrum if you only want to hit the Categories property for a small subset of the returned values, lazy loading might be beneficial.

Categories