-
Notifications
You must be signed in to change notification settings - Fork 23
K voland #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: K-Voland
Are you sure you want to change the base?
K voland #48
Conversation
|
Я пока плохо представляю как списки эти работают, но для одинокого кролика оно работает. |
|
Вроде что-то начал понимать, теперь оно нормально работает. |
CourseApp/RabbitInfo.cs
Outdated
| public class Rabbit | ||
| { | ||
| public void RabbitInfo(string Name, string Pearent1,string Pearent2, List<string> Child) | ||
| {Console.Write($"Кролик {Name}, Родители: {Pearent1} и {Pearent2}, Дети: ");foreach(var i in Child){Console.WriteLine($"{i} ");}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Разбейте на несколько строк, читать очень сложно
CourseApp/Menu.cs
Outdated
| { | ||
| public class Menu:Farm | ||
| { | ||
| public Rabbit info = new Rabbit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
имя переменной не информативно - info? но при этом класс кролика
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если это меню, то это толкьо меню!
CourseApp/Menu.cs
Outdated
|
|
||
| namespace CourseApp | ||
| { | ||
| public class Menu:Farm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут наследование не совсем верно применено - ну или как минимум именование - мен. не является фермой
| var krosh = new Rabbit(); | ||
| var N ="momo"; | ||
| krosh.RabbitInfo(N); | ||
| Assert.Equal("momo",N); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
этот тест не проверяет ващ класс - он только проверяет что переменная N, объявленная в тесте = "momo"
| var P1 = "mu"; | ||
| var P2 = "nu"; | ||
| krosh.RabbitInfo(N); | ||
| Assert.Equal("momo",N); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Та же беда - вы проверяете не свойство класса, а проверяете значение переменных, которые объявлены в тесте
CourseApp/Zoo.cs
Outdated
| { | ||
| public class Zoo | ||
| { | ||
| public ArrayList Klet = new ArrayList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Используйте более понятное название - KLet? может Kletka?
CourseApp/Zoo.cs
Outdated
|
|
||
| set | ||
| { | ||
| foreach(NewPet i in Klet) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://metanit.com/sharp/tutorial/4.9.php - лучше использовать именно словарь
CourseApp/Krolik.cs
Outdated
|
|
||
| namespace CourseApp | ||
| { | ||
| public class Krolik : Zoo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Почему кролик наследует зоопарк? Тут с именованием явная беда - при наследовании у нас отошение is-A - "является" . Кролик вряд ли является зоопарком :(
CourseApp/Krolik.cs
Outdated
| Klet.Add(new NewPet(Name, Pearent1, Pearent2)); | ||
| foreach(NewPet i in Klet) | ||
| { | ||
| if(Pearent1 == i.Name || Pearent2 == i.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А как же первых добавить?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Покупая в магазине мы не знаем кто родители, потому иногда эти свойства могут отсутствовать.)
CourseApp/Pet.cs
Outdated
| { | ||
| public abstract class Pet | ||
| { | ||
| private Dictionary<string, NewPet> spisok = new Dictionary<string, NewPet>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Думаю что это уже не список - поэтому лучше называть переменну. так, что это будет отражать сущность
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Что-то совсем не приходит ничего в голову. По моему это как раз список животных с их родителями и потомками.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не нужно вам это внутри домашнего животного
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я сейчас залью исправления и открою PR в ваш репозитарий
|
Проблем много, ещё буду править. Это не окончательная версия, просто хочется услышать комментарии. |
|
Видимо я что-то не понимаю в устройстве записи памяти. Обращаясь к BuyPet из Menu я вроде должен создать новую запись в словаре, но потом когда хочу получить обратно пишет что не найден такой ключ. Что я не так делаю? |
CourseApp/Krolik.cs
Outdated
| public override void BuyPet() | ||
| { | ||
| Console.Write("Введите имя купленного кролика: "); | ||
| Name = Console.ReadLine(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не не - это - плохая идея - обработку пользовательского ввода вести в классахз, фактически представляюзих модели данных - уберите, а Name передавайте как параметр метода. И сразу подумайте - а как это протестировать?
|
|
||
| public override void NewPet() | ||
| { | ||
| Console.Write("Введите имя новорожденного кролика: "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
то же самое - вынесите в основную программу получение параметров, а здесь, только их проверьте
CourseApp/Menu.cs
Outdated
| Vid = Console.ReadLine(); | ||
| if (Vid == "rabbit") | ||
| { | ||
| krosh.BuyPet(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если вы даете пользователю выбрать что купить... то почему не создать ресурся здесь а не выше (экземпляры классов) - и вызовутся только тогда, когда пользователь определиться - кроша или кролика
CourseApp/Menu.cs
Outdated
| } | ||
|
|
||
| break; | ||
| case "Sel": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут так просто не разобраться, попробую завтра переписать по другому
CourseApp/NewPet.cs
Outdated
|
|
||
| namespace CourseApp | ||
| { | ||
| public class NewPet : Pet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Очень плохое название NewPet создается вот так - new Pet(), а тут все таки какая то иерархия
CourseApp/Pet.cs
Outdated
|
|
||
| public List<string> Child { get => child; set => child = value; } | ||
|
|
||
| public string Vid {get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe Type?
CourseApp/Cavy.cs
Outdated
| { | ||
| public class Cavy : AbstractPet | ||
| { | ||
| public override void BuyPet() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не дело морской свинки продавать домашние животные :)
|
|
||
| public override void NewPet() | ||
| { | ||
| Console.Write("Введите имя новорожденной морской свинки: "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Осуществлять пользовательский ввод тоже не надо в классах, которые представляют сущности
| public override void NewPet() | ||
| { | ||
| Console.Write("Введите имя новорожденной морской свинки: "); | ||
| Name = Console.ReadLine(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вот для всего этого есть порождающий паттерн фабрика. или фабричный метод - как раз для реализации вашей идеи
| { | ||
| Console.Write("Введите имя новорожденной морской свинки: "); | ||
| Name = Console.ReadLine(); | ||
| Console.WriteLine("Введите имена родителй морской свинки: "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А саму логику создания и внесения родителей следует унести в конструктор класса
|
|
||
| public string Pearent2 {get; set; } | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type - тут будет определятся типом наследника, так что тоже не надо
CourseApp/Cavy.cs
Outdated
| } | ||
| } | ||
|
|
||
| public override string ToString() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Утаскиваю в родительский класс
|
|
||
| public string Pearent2 {get; set; } | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это позволяет заставить тех, кто реализует наследников поддреживать метод ToString - они просто обязаны будут реализовать GetInfo - который toString и вернет, в противном случае - никто не заставит их реализовать toString - и в какой то момент про это забудут
CourseApp/NewPet.cs
Outdated
| this.Vid = v; | ||
| } | ||
|
|
||
| public NewPet(string child, string v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Название было плохое :(
CourseApp/Menu.cs
Outdated
| --(')('),,)-(')('),,)---(')_(')---(..(')(')-(..(')(') "); | ||
| } | ||
|
|
||
| private void PetInfo(NewPet i, string name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это уже поддерживают сами pet - у них to string реализован
CourseApp/Menu.cs
Outdated
| Krolik krosh = new Krolik(); | ||
| Cavy cavy = new Cavy(); | ||
| switch(go) | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вот это максимально похоже а идею фабричного метода и его следует вынести отдельно, но пока для упрощения оставим как есть
CourseApp/Menu.cs
Outdated
|
|
||
| break; | ||
| case "Sel": | ||
| Console.WriteLine("Введите кого вы хоите разводить: rabbit/cavy"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Было дублирование кода
CourseApp/Menu.cs
Outdated
| case "Inf": | ||
| { | ||
| { | ||
| Console.Write("Введите имя животного о котором хотите унать: "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это следует убрать - не дело меню про это знать
| Spisok.Add(Name, new NewPet("rabbit")); | ||
| } | ||
|
|
||
| public override void NewPet() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это теперь делает базовый класс, только передавайте
| Spisok.Add(Name, new NewPet("cavy")); | ||
| } | ||
|
|
||
| public override void NewPet() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Опять же это теперь делает базовый класс, можно убирать
No description provided.