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