Add documentation and contracts for domain types.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
class AUTHOR
|
||||
|
||||
class
|
||||
AUTHOR
|
||||
|
||||
create
|
||||
make
|
||||
@@ -6,19 +8,26 @@ create
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_name: STRING_32)
|
||||
-- Create an author with `a_name' as `name'.
|
||||
do
|
||||
set_name (a_name)
|
||||
ensure
|
||||
name_set: name = a_name
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING_32
|
||||
-- Author name
|
||||
|
||||
feature -- Status setting
|
||||
feature -- Change
|
||||
|
||||
set_name (a_name: STRING_32)
|
||||
-- Set `name' with `a_name'.
|
||||
do
|
||||
name := a_name
|
||||
ensure
|
||||
name_set: name = a_name
|
||||
end
|
||||
|
||||
end -- class AUTHOR
|
||||
|
||||
@@ -1,40 +1,60 @@
|
||||
class BOOK
|
||||
|
||||
class
|
||||
BOOK
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_title: STRING_32; an_author: AUTHOR; an_isbn: STRING_32)
|
||||
make (a_title: STRING_32; a_author: AUTHOR; a_isbn: STRING_32)
|
||||
-- Create a book with `a_title' as `title',
|
||||
-- `a_author' as `author', and `a_isbn' as `isbn',
|
||||
do
|
||||
set_title (a_title)
|
||||
set_author (an_author)
|
||||
set_isbn (an_isbn)
|
||||
set_author (a_author)
|
||||
set_isbn (a_isbn)
|
||||
ensure
|
||||
title_set: title = a_title
|
||||
author_set: author = a_author
|
||||
isbn_set: isbn = a_isbn
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
title: STRING_32
|
||||
-- Main title.
|
||||
|
||||
isbn: STRING_32
|
||||
-- ISBN.
|
||||
|
||||
author: AUTHOR
|
||||
-- Author.
|
||||
|
||||
feature -- Status setting
|
||||
feature -- Change
|
||||
|
||||
set_title (a_title: STRING_32)
|
||||
-- Set `title' with `a_title'.
|
||||
do
|
||||
title := a_title
|
||||
ensure
|
||||
title_set: title = a_title
|
||||
end
|
||||
|
||||
set_author (an_author: AUTHOR)
|
||||
set_author (a_author: AUTHOR)
|
||||
-- Set `author' with `a_author'.
|
||||
do
|
||||
author := an_author
|
||||
author := a_author
|
||||
ensure
|
||||
author_set: author = a_author
|
||||
end
|
||||
|
||||
set_isbn (an_isbn: STRING_32)
|
||||
set_isbn (a_isbn: STRING_32)
|
||||
-- Set `isbn' with `a_isbn'.
|
||||
do
|
||||
isbn := an_isbn
|
||||
isbn := a_isbn
|
||||
ensure
|
||||
isbn_set: isbn = a_isbn
|
||||
end
|
||||
|
||||
end -- class BOOK
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class BOOK_COLLECTION
|
||||
class
|
||||
BOOK_COLLECTION
|
||||
|
||||
create
|
||||
make
|
||||
@@ -6,75 +7,72 @@ create
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_name: STRING_32)
|
||||
-- Create a collection of book with `a_name' as `name'
|
||||
do
|
||||
set_name (a_name)
|
||||
create book_index.make (10)
|
||||
ensure
|
||||
name_set: name = a_name
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING_32
|
||||
-- Name.
|
||||
|
||||
books: LIST [BOOK]
|
||||
-- collection of book.
|
||||
do
|
||||
from
|
||||
create {LINKED_LIST [BOOK]} Result.make
|
||||
book_index.start
|
||||
until
|
||||
book_index.after
|
||||
loop
|
||||
Result.append (book_index.item_for_iteration)
|
||||
book_index.forth
|
||||
create {LINKED_LIST [BOOK]} Result.make
|
||||
across book_index as it loop
|
||||
Result.append (it.item)
|
||||
end
|
||||
end
|
||||
|
||||
books_by_author (an_author: STRING_32): detachable LIST [BOOK]
|
||||
books_by_author (a_author: STRING_32): LIST [BOOK]
|
||||
-- Books wrote by `a_author' in this collection.
|
||||
do
|
||||
if book_index.has (an_author) then
|
||||
Result := book_index @ an_author
|
||||
if attached book_index [a_author] as l_result then
|
||||
Result := l_result
|
||||
else
|
||||
create {LINKED_LIST [BOOK]} Result.make
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Status setting
|
||||
feature -- Change
|
||||
|
||||
set_name (a_name: STRING_32)
|
||||
-- Set `name' with `a_name'.
|
||||
do
|
||||
name := a_name
|
||||
ensure
|
||||
name_set: name = a_name
|
||||
end
|
||||
|
||||
add_book (a_book: BOOK)
|
||||
-- Extend collection with `a_book'.
|
||||
local
|
||||
l: detachable LIST [BOOK]
|
||||
do
|
||||
if book_index.has (a_book.author.name) then
|
||||
l := book_index.at ( a_book.author.name )
|
||||
else
|
||||
l := book_index.at (a_book.author.name )
|
||||
if l = Void then
|
||||
create {LINKED_LIST [BOOK]} l.make
|
||||
book_index.put (l, a_book.author.name)
|
||||
end
|
||||
if attached l as la then
|
||||
la.force (a_book)
|
||||
end
|
||||
|
||||
l.force (a_book)
|
||||
end
|
||||
|
||||
add_books (book_list: like books)
|
||||
|
||||
-- Append collection with `book_list'.
|
||||
do
|
||||
from
|
||||
book_list.start
|
||||
until
|
||||
book_list.after
|
||||
loop
|
||||
add_book (book_list.item)
|
||||
book_list.forth
|
||||
across book_list as it loop
|
||||
add_book (it.item)
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
book_index: HASH_TABLE [LIST [BOOK], STRING_32]
|
||||
-- Association of author name and its books.
|
||||
|
||||
end -- class BOOK_COLLECTION
|
||||
|
||||
Reference in New Issue
Block a user