https://github.com/lightforever/oop
https://github.com/lightforever/oop
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/lightforever/oop
- Owner: lightforever
- Created: 2017-02-26T17:35:10.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-26T17:55:08.000Z (over 9 years ago)
- Last Synced: 2025-02-03T12:51:20.298Z (over 1 year ago)
- Language: C#
- Size: 2.35 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
###Задача по паттернам проектирования/ООП/чистоте кода###
Реализация: Visual Studio 2013, C#
------
Пусть у нас имеется база книжных магазинов заданна¤ массивом ссылок:
IObjectReference[] bookStores
Необходимо продумать API (набор классов, методов) для выполнения стандартных запросов к этой "базе данных" - например, поиск книг с заданным названием или автором, поиск книг, толщина которых находится в требуемом диапазоне; вычисление общего количества страниц, написанных одним автором и т. п. основное внимание необходимо уделить вопросам удобства и безопасности использовани¤ предложенного решения клиентским кодом.
API Reference
public interface IObjectReference
{
IObjectReference Parent { get; } // will return null if there is no parent object in hierarchy
// will return null if property is not found or if property value is an inferior object(s) of type IObjectReference
object GetValueOfProperty(
string propertyName); // will throw if null or empty
}
public static class BookStoreUtils
{
// will return null if property is not found
public static IObjectReference[] GetInferiorObjects(
IObjectReference propertyOwner, // will throw if null
string propertyName) // will throw if null or empty
}
Objects Hierarchy:
BookStore : IObjectReference
Has access to collections of Books objects
Properties:
- IObjectReference[] Books
Book : IObjectReference
Represents particular book. Returns BookStore reference as it's parent.
Properties:
- string Author
- string Title
- int NumberOfPages
UsageExamples:
// given IObjectReference to book object (book)
string author = (string)book.GetValueOfProperty("Author");
// given IObjectReference to book store object (store)
IObjectReference firstBook = BookStoreUtils.GetInferiorObjects(store, "Books")[0];
int firstBookPagesCount = (int)firstBook.GetValueOfProperty("NumberOfPages");