diff --git a/.vscode/markdown.code-snippets b/.vscode/markdown.code-snippets index 01e8643..5429f63 100644 --- a/.vscode/markdown.code-snippets +++ b/.vscode/markdown.code-snippets @@ -68,10 +68,10 @@ }, "exercise slide" : { "scope": "markdown", - "prefix": "\"exercise invert\"", + "prefix": "exercise", "body": [ "## Exercise $0.", - "", + "", ], "description": "Exercise slide colors" }, diff --git a/10-static-members-methods-and-classes-slides.html b/10-static-members-methods-and-classes-slides.html index 0862954..bc73ff7 100644 --- a/10-static-members-methods-and-classes-slides.html +++ b/10-static-members-methods-and-classes-slides.html @@ -1,4 +1,4 @@ -
interface IUser
+{
+ int Id { get; set; }
+ string Name { get; set; }
+ void GetUserStatistics();
+}
+
+I
to more easily identify them as interfaces and not classesclass User : IUser
+{
+
+}
+
+class User : IUser
+{
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public void GetUserStatistics()
+ {
+ // Some code here
+ }
+}
+
+class Rock : IPickable, IThrowable, ICrushable
+{
+// Code that implements IPickable, IThrowable and ICrushable
+}
+
+public void DeleteData(IDeletable data)
+{
+ data.Delete();
+}
+
+IDeletable
, regardless of other functionalityclass Dog |
+class Human |
+class Bear |
+
---|---|---|
Eat() |
+Eat() |
+Eat() |
+
Sleep() |
+Sleep() |
+Sleep() |
+
WagTail() |
+Contemplate() |
+Hibernate() |
+
Animal
, which has methods Eat()
and Sleep()
Eat()
and Sleep()
?class Tree |
+class Human |
+class Car |
+
---|---|---|
Grow() |
+Grow() |
+Explode() |
+
Photosynthesize() |
+Move() |
+Move() |
+
IGrowable
and IMovable
IMovable
) and one for all objects that can be carried (ICarryable
)interface IMovable
+{
+ void Move();
+}
+interface ICarryable
+{
+ void Carry();
+}
+
+class Elephant : IMovable
+{
+ public void Move()
+ {
+ Console.WriteLine("The elephant is moving'");
+ }
+}
+class Cat : IMovable, ICarryable
+{
+ public void Move()
+ {
+ Console.WriteLine("The cat is moving'");
+ }
+ public void Carry()
+ {
+ Console.WriteLine("You are carrying the cat");
+ }
+}
+class Rock : ICarryable
+{
+ public void Carry()
+ {
+ Console.WriteLine("You are carrying the rock");
+ }
+}
+
+class Program
+{
+ static void Main(string[] args)
+ {
+ Elephant elephant = new Elephant();
+ Cat cat = new Cat();
+ Rock rock = new Rock();
+
+ List<IMovable> movables =
+ new List<IMovable>{ elephant, cat };
+ List<ICarryable> carryables =
+ new List<ICarryable>{ cat, rock };
+
+ foreach (IMovable movable in movables)
+ movable.Move();
+
+ foreach (ICarryable carryable in carryables)
+ carryable.Carry();
+ }
+}
+
+Create a console application that has an interface IInfo
and two classes Product
and Category
that both implement IInfo
.
IInfo
, declare a property InfoText
and a method PrintInfo
Product
and Category
IInfo
, and add the products and categories to itIComparable
InterfaceCreate a program that sorts a list of shapes by area, using the IComparable interface which is used by the List.Sort()
method to know whether the elements should come before or after each other in the list.
Shape
, Square
, Triangle
, and Circle
. Square
, Triangle
and Circle
inherit from Shape
, which implements the IComparable<Shape>
interface.double Area
. Square
, Triangle
and Circle
have to have constructors to calculate the area: Square
and Triangle
with length
and height
, and Circle
with radius
.The CompareTo(Shape? other)
method should return 1
if the area is greater than what is being compared with (Shape other
), 0
if the areas are equal, and -1
if the area is smaller..Sort()
method.foreach
loop. They should be printed in an increasing order.