Merineth πŸ‡ΈπŸ‡ͺ
Merineth πŸ‡ΈπŸ‡ͺ
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/13/2024 in #help
βœ… Factory method
Would that be all?
5 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/13/2024 in #help
βœ… Factory method
does it imply that we put the new in a different class and not in the main program?
5 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/13/2024 in #help
βœ… Factory method
// A general toy class
abstract class Toy
{
public abstract void Play();
}

// Specific types of toys
class Car : Toy
{
public override void Play()
{
Console.WriteLine("Vroom! I'm a car.");
}
}

class Doll : Toy
{
public override void Play()
{
Console.WriteLine("Hi! I'm a doll.");
}
}

// The factory method
abstract class ToyFactory
{
public abstract Toy CreateToy();
}

class CarFactory : ToyFactory
{
public override Toy CreateToy()
{
return new Car();
}
}

class DollFactory : ToyFactory
{
public override Toy CreateToy()
{
return new Doll();
}
}

// Using the factory method
class Program
{
static void Main(string[] args)
{
ToyFactory carFactory = new CarFactory();
Toy car = carFactory.CreateToy();
car.Play(); // Output: Vroom! I'm a car.

ToyFactory dollFactory = new DollFactory();
Toy doll = dollFactory.CreateToy();
doll.Play(); // Output: Hi! I'm a doll.
}
}
// A general toy class
abstract class Toy
{
public abstract void Play();
}

// Specific types of toys
class Car : Toy
{
public override void Play()
{
Console.WriteLine("Vroom! I'm a car.");
}
}

class Doll : Toy
{
public override void Play()
{
Console.WriteLine("Hi! I'm a doll.");
}
}

// The factory method
abstract class ToyFactory
{
public abstract Toy CreateToy();
}

class CarFactory : ToyFactory
{
public override Toy CreateToy()
{
return new Car();
}
}

class DollFactory : ToyFactory
{
public override Toy CreateToy()
{
return new Doll();
}
}

// Using the factory method
class Program
{
static void Main(string[] args)
{
ToyFactory carFactory = new CarFactory();
Toy car = carFactory.CreateToy();
car.Play(); // Output: Vroom! I'm a car.

ToyFactory dollFactory = new DollFactory();
Toy doll = dollFactory.CreateToy();
doll.Play(); // Output: Hi! I'm a doll.
}
}
5 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/11/2024 in #help
βœ… Can someone explain Delegates to me like i'm 5?
Anyhow i'll continue with my studies (not delegates) thanks for tthe help!
322 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/11/2024 in #help
βœ… Can someone explain Delegates to me like i'm 5?
thanks course responsible
322 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/11/2024 in #help
βœ… Can someone explain Delegates to me like i'm 5?
πŸ’€ ok this is wayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy to complicated
322 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/11/2024 in #help
βœ… Can someone explain Delegates to me like i'm 5?
Shouldn't the Action<T>have two parameters?
322 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/11/2024 in #help
βœ… Can someone explain Delegates to me like i'm 5?
Can the Action<T> class be replaced with a user- defined delegate type with the same functionality?
322 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/11/2024 in #help
βœ… Can someone explain Delegates to me like i'm 5?
Or are there no lambda expression in this code
322 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/11/2024 in #help
βœ… Can someone explain Delegates to me like i'm 5?
Am i high?
322 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/11/2024 in #help
βœ… Can someone explain Delegates to me like i'm 5?
No description
322 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/11/2024 in #help
βœ… Can someone explain Delegates to me like i'm 5?
and it's kind of complex
322 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/11/2024 in #help
βœ… Can someone explain Delegates to me like i'm 5?
We were only given one exercise which includes lambda ...
322 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/11/2024 in #help
βœ… Can someone explain Delegates to me like i'm 5?
Not sure how i'm gonna practice it tho
322 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/11/2024 in #help
βœ… Can someone explain Delegates to me like i'm 5?
But yea i got a decent basic understanding of delegates now
322 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/11/2024 in #help
βœ… Can someone explain Delegates to me like i'm 5?
purely for the dev convience (except me)
322 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/11/2024 in #help
βœ… Can someone explain Delegates to me like i'm 5?
Makes sense
322 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/11/2024 in #help
βœ… Can someone explain Delegates to me like i'm 5?
Does it become easier for the CPU to handle if we use delegates, or is it purely for the dev?
322 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/11/2024 in #help
βœ… Can someone explain Delegates to me like i'm 5?
So essentially, delegates, func, action and lambda are things in C# to make code faster to write and easier to read?
322 replies
CC#
Created by Merineth πŸ‡ΈπŸ‡ͺ on 10/11/2024 in #help
βœ… Can someone explain Delegates to me like i'm 5?
just instantly used
322 replies