Object? You Keep Using that Word
-
Upload
kevlin-henney -
Category
Software
-
view
754 -
download
3
Transcript of Object? You Keep Using that Word
![Page 1: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/1.jpg)
Object? You keep
using that word...
@KevlinHenney
![Page 2: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/2.jpg)
![Page 3: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/3.jpg)
![Page 4: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/4.jpg)
/ WordFriday
![Page 5: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/5.jpg)
Agglutination is a process in linguistic morphology
derivation in which complex words are formed by
stringing together morphemes, each with a single
grammatical or semantic meaning. Languages that
use agglutination widely are called agglutinative
languages.
http://en.wikipedia.org/wiki/Agglutination
![Page 6: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/6.jpg)
pneumonoultramicroscopicsilicovolcanoconiosis
Rindfleischetikettierungsüberwachungsaufgabenübertragungsgesetz
fylkestrafikksikkerhetsutvalgssekretariatslederfunksjonene
muvaffakiyetsizleştiricileştiriveremeyebileceklerimizdenmişsinizcesine
hippopotomonstrosesquipedaliophobia
![Page 7: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/7.jpg)
http://www.bonkersworld.net/object-world/
![Page 8: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/8.jpg)
http://www.bonkersworld.net/object-world/
OBJECT-ORIENTED
VenetianBlind Door
Television
Picture Glass
Sofa TelevisionRemoteControl
Peephole
![Page 9: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/9.jpg)
![Page 10: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/10.jpg)
People will be using the
words you choose in their
conversation for the next 20
years. You want to be sure
you do it right.
Unfortunately, many people
get all formal [...]. Just calling
it what it is isn't enough.
![Page 11: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/11.jpg)
They have to tack on a
flowery, computer science-y,
impressive sounding, but
ultimately meaningless word,
like Object, Thing,
Component, Part, Manager,
Entity, or Item.
![Page 12: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/12.jpg)
http://classnamer.com/
![Page 13: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/13.jpg)
http://methodnamer.com/
![Page 14: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/14.jpg)
public interface BookEntity ... public interface BookEntityFactory ... public interface ISBNValidator ... public interface CatalogueRepository ... public interface CatalogueRepositoryProvider ... public abstract class AbstractBookEntity implements BookEntity public class BookEntityImpl extends AbstractBookEntity ... public class BookEntityFactoryImpl implements BookEntityFactory ... public class ISBNValidatorImpl implements ISBNValidator ... public class CatalogueRepositoryImpl implements CatalogueRepository ... public class CatalogueRepositoryProviderImpl implements CatalogueRepositoryProvider ...
![Page 15: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/15.jpg)
public interface Book ... public final class ISBN ... public interface Catalogue ... public class DescriptionOfCatalogueImplementation implements Catalogue ...
![Page 16: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/16.jpg)
managerialism, noun
belief in or reliance on the use of professional
managers in administering or planning an activity
application of managerial techniques of businesses
to the running of other organisations, such as the
civil service or local authorities
belief in the importance of tightly managed
organisations, as opposed to individuals, or
groups that do not resemble an organisation
Concise Oxford English Dictionary ∙ Dictionary.com ∙ Wikipedia
![Page 17: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/17.jpg)
One way to name classes is to
give each a unique name,
indicative of its purpose. Unique
names give you the opportunity
to convey a lot of information
without creating names that are
long and unwieldy.
This is exactly the right thing to do
if the names are in common use.
![Page 18: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/18.jpg)
Loan Member BookCopy
![Page 19: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/19.jpg)
Loan IMember IBookCopy
Member BookCopy
![Page 20: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/20.jpg)
Loan
Member BookCopy
![Page 21: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/21.jpg)
role, noun
an actor's part in a play, film, etc.
a person or thing's function in a particular
situation
a function, part or expected behaviour
performed in a particular operation or process
Concise Oxford English Dictionary ∙ Merriam-Webster's Collegiate Dictionary
![Page 22: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/22.jpg)
Loan Borrower LoanItem
Member BookCopy
![Page 23: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/23.jpg)
interface
![Page 24: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/24.jpg)
Tree Builder Parser
![Page 25: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/25.jpg)
Tree Builder Parser
BuilderImpl
![Page 26: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/26.jpg)
Tree ParserListener Parser
Builder
![Page 27: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/27.jpg)
Tree
ParserListener Parser
Builder
![Page 28: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/28.jpg)
You can communicate how the new
class is the same by naming some
superclass. It need not be the
immediate superclass, if some distant
ancestor communicates more
clearly.
You can communicate how the new
class is different by finding a word
that accurately highlights the reason
the new class isn't just the superclass.
![Page 29: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/29.jpg)
Connection Connection
Factory
Connection
Impl
![Page 30: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/30.jpg)
Connection Connection
Pool
Pooled
Connection
![Page 31: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/31.jpg)
public Connection createConnection(Provider provider) throws ConnectionFailureException ...
![Page 32: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/32.jpg)
public Connection connectTo(Provider ofUpdates) throws ConnectionFailure ...
![Page 33: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/33.jpg)
OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I'm not aware of them.
Alan Kay
![Page 34: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/34.jpg)
William Cook, "On Understanding Data Abstraction, Revisited"
![Page 35: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/35.jpg)
Ignorance
Apathy
Selfishness
![Page 36: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/36.jpg)
Identity
State
Behaviour
![Page 37: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/37.jpg)
![Page 38: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/38.jpg)
Stack
![Page 39: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/39.jpg)
Stack {push, pop, depth, top}
![Page 40: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/40.jpg)
Stack[T] {
push(T), pop(), depth() : Integer, top() : T
}
![Page 41: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/41.jpg)
An interface is a contract to deliver
a certain amount of service.
Clients of the interface depend on
the contract, which is usually
documented in the interface
specification.
Butler W Lampson
"Hints for Computer System Design"
![Page 42: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/42.jpg)
![Page 43: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/43.jpg)
Stack[T] {
push(T item), pop(), depth() : Integer, top() : T
}
given: before = depth() postcondition: depth() = before + 1 ∧ top() = item
precondition: depth() > 0
given: before = depth() precondition: before > 0 postcondition: depth() = before – 1
given: result = depth() postcondition: result ≥ 0
![Page 44: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/44.jpg)
![Page 45: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/45.jpg)
alphabet(Stack) = {push, pop, depth, top}
![Page 46: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/46.jpg)
trace(Stack) = {⟨ ⟩, ⟨push⟩, ⟨depth⟩, ⟨push, pop⟩, ⟨push, top⟩, ⟨push, depth⟩, ⟨push, push⟩, ⟨depth, push⟩, ⟨depth, depth⟩, ⟨push, push, pop⟩, ...}
![Page 47: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/47.jpg)
Non-Empty Empty
depth depth top push pop [depth > 1]
push
pop [depth = 1]
![Page 48: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/48.jpg)
public class Stack_spec { public static class A_new_stack { @Test public void has_no_depth() @Test() public void has_no_top() }
public static class An_empty_stack { @Test() public void throws_when_popped() @Test public void acquires_depth_by_retaining_a_pushed_item_as_its_top() }
public static class A_non_empty_stack { @Test public void becomes_deeper_by_retaining_a_pushed_item_as_its_top() @Test public void on_popping_reveals_tops_in_reverse_order_of_pushing() } }
![Page 49: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/49.jpg)
public class Stack_spec { public static class A_new_stack { @Test public void has_no_depth() @Test() public void has_no_top() }
public static class
An_empty_stack { @Test() public void throws_when_popped() @Test public void acquires_depth_by_retaining_a_pushed_item_as_its_top() }
public static class
A_non_empty_stack { @Test public void becomes_deeper_by_retaining_a_pushed_item_as_its_top() @Test public void on_popping_reveals_tops_in_reverse_order_of_pushing() } }
![Page 50: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/50.jpg)
public class Stack_spec { public static class A_new_stack { @Test public void has_no_depth() @Test() public void has_no_top() }
public static class
An_empty_stack { @Test() public void throws_when_popped() @Test public void acquires_depth_by_retaining_a_pushed_item_as_its_top() }
public static class
A_non_empty_stack { @Test public void becomes_deeper_by_retaining_a_pushed_item_as_its_top() @Test public void on_popping_reveals_tops_in_reverse_order_of_pushing() } }
![Page 51: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/51.jpg)
![Page 52: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/52.jpg)
Many objects have no conceptual
identity. These objects describe
some characteristic of a thing.
![Page 53: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/53.jpg)
When you care only about the
attributes of an element of the
model, classify it as a value
object. Make it express the
meaning of the attributes it
conveys and give it related
functionality. Treat the value
object as immutable. Don't give it
any identity and avoid the design
complexities necessary to
maintain entities.
![Page 54: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/54.jpg)
Identity
State
Behaviour
![Page 55: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/55.jpg)
Identity
State
Behaviour
![Page 56: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/56.jpg)
Encapsulation
Inheritance
Polymorphism
![Page 57: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/57.jpg)
Encapsulation
Polymorphism
Inheritance
![Page 58: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/58.jpg)
Encapsulation
Polymorphism
Inheritance
![Page 59: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/59.jpg)
encapsulate, verb
enclose (something) in or as if in a capsule.
express the essential feature of (someone or something) succinctly.
provide an interface for (a piece of software or hardware) to allow or simplify access for the user.
The New Oxford Dictionary of English
![Page 60: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/60.jpg)
In many object-oriented programming languages the concept of inheritance is present, which provides a mechanism for sharing code among several classes of objects. Many people even regard inheritance as the hallmark of object-orientedness in programming languages. We do not agree with this view, and argue that the essence of object-oriented programming is the encapsulation of data and operations in objects and the protection of individual objects against each other.
Pierre America "A Behavioural Approach to Subtyping in Object-Oriented Programming Languages"
![Page 61: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/61.jpg)
In many object-oriented programming languages the concept of inheritance is present, which provides a mechanism for sharing code among several classes of objects. Many people even regard inheritance as the hallmark of object-orientedness in programming languages. We do not agree with this view, and argue that the essence of object-oriented programming is the encapsulation of data and operations in objects and the protection of individual objects against each other.
The author considers this principle of protection of objects against each other as the basic and essential characteristic of object-oriented programming. It is a refinement of the technique of abstract data types, because it does not only protect one type of objects against all other types, but one object against all other ones. As a programmer we can consider ourselves at any moment to be sitting in exactly one object and looking at all the other objects from outside.
Pierre America "A Behavioural Approach to Subtyping in Object-Oriented Programming Languages"
![Page 62: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/62.jpg)
![Page 63: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/63.jpg)
Object-oriented programming does not have an exclusive claim to all these good properties. Systems may be modeled by other paradigms.
Resilience can be achieved just as well by organizing programs around abstract data types, independently of taxonomies; in fact, data abstraction alone is sometimes taken as the essence of object orientation.
![Page 64: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/64.jpg)
abstraction, n. (Logic)
the process of formulating a generalized concept of
a common property by disregarding the differences
between a number of particular instances. On such
an account, we acquired the concept of red by
recognizing it as common to, and so abstracting it
from the other properties of, those individual
objects we were originally taught to call red.
an operator that forms a class name or predicate
from any given expression.
E J Borowski and J M Borwein
Dictionary of Mathematics
![Page 65: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/65.jpg)
T RecentlyUsedList {
new : RecentlyUsedList[T], isEmpty : RecentlyUsedList[T] Boolean,
size : RecentlyUsedList[T] Integer,
add : RecentlyUsedList[T] T RecentlyUsedList[T],
get : RecentlyUsedList[T] Integer T,
equals : RecentlyUsedList[T] RecentlyUsedList[T] Boolean }
![Page 66: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/66.jpg)
public class RecentlyUsedList
{
private …
public boolean isEmpty() …
public int size() …
public void add(String toAdd) …
public String get(int index) …
public boolean equals(RecentlyUsedList other) …
}
![Page 67: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/67.jpg)
public class RecentlyUsedList
{
private …
public boolean isEmpty() …
public int size() …
public void add(String toAdd) …
public String get(int index) …
public boolean equals(RecentlyUsedList other) …
public boolean equals(Object other) …
}
![Page 68: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/68.jpg)
public class RecentlyUsedList
{
private List<String> items = new ArrayList<String>();
public boolean isEmpty()
{
return items.isEmpty();
}
public int size()
{
return items.size();
}
public void add(String toAdd)
{
items.remove(toAdd);
items.add(toAdd);
}
public String get(int index)
{
return items.get(size() – index – 1);
}
public boolean equals(RecentlyUsedList other)
{
return other != null && items.equals(other.items);
}
public boolean equals(Object other)
{
return
other instanceof RecentlyUsedList &&
equals((RecentlyUsedList) other);
}
}
![Page 69: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/69.jpg)
typedef struct RecentlyUsedList RecentlyUsedList;
RecentlyUsedList * create();
void destroy(RecentlyUsedList *);
bool isEmpty(const RecentlyUsedList *);
int size(const RecentlyUsedList *);
void add(RecentlyUsedList *, int toAdd);
int get(const RecentlyUsedList *, int index);
bool equals(const RecentlyUsedList *, const RecentlyUsedList *);
![Page 70: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/70.jpg)
struct RecentlyUsedList
{
int * items;
int length;
};
![Page 71: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/71.jpg)
RecentlyUsedList * create()
{
RecentlyUsedList * result = (RecentlyUsedList *) malloc(sizeof(RecentlyUsedList));
result->items = 0;
result->length = 0;
return result;
}
void destroy(RecentlyUsedList * self)
{
free(self->items);
free(self);
}
bool isEmpty(const RecentlyUsedList * self)
{
return self->length == 0;
}
int size(const RecentlyUsedList * self)
{
return self->length;
}
static int indexOf(const RecentlyUsedList * self, int toFind)
{
int result = -1;
for(int index = 0; result == -1 && index != self->length; ++index)
if(self->items[index] == toFind)
result = index;
return result;
}
static void removeAt(RecentlyUsedList * self, int index)
{
memmove(&self->items[index], &self->items[index + 1], (self->length - index - 1) * sizeof(int));
--self->length;
}
void add(RecentlyUsedList * self, int toAdd)
{
int found = indexOf(self, toAdd);
if(found != -1)
removeAt(self, found);
self->items = (int *) realloc(self->items, (self->length + 1) * sizeof(int));
self->items[self->length] = toAdd;
++self->length;
}
int get(const RecentlyUsedList * self, int index)
{
return self->items[self->length - index - 1];
}
bool equals(const RecentlyUsedList * lhs, const RecentlyUsedList * rhs)
{
return lhs->length == rhs->length && memcmp(lhs->items, rhs->items, lhs->length * sizeof(int)) == 0;
}
![Page 72: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/72.jpg)
struct RecentlyUsedList
{
std::vector<int> items;
};
![Page 73: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/73.jpg)
extern "C"
{
RecentlyUsedList * create()
{
return new RecentlyUsedList;
}
void destroy(RecentlyUsedList * self)
{
delete self;
}
bool isEmpty(const RecentlyUsedList * self)
{
return self->items.empty();
}
int size(const RecentlyUsedList * self)
{
return self->items.size();
}
void add(RecentlyUsedList * self, int toAdd)
{
std::vector<int>::iterator found =
std::find(self->items.begin(), self->items.end(), toAdd);
if(found != self->items.end())
self->items.erase(found);
self->items.push_back(toAdd);
}
int get(const RecentlyUsedList * self, int index)
{
return self->items[self->items.size() - index - 1];
}
bool equals(const RecentlyUsedList * lhs, const RecentlyUsedList * rhs)
{
return lhs->items == rhs->items;
}
}
![Page 74: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/74.jpg)
OO ≡ ADT?
![Page 75: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/75.jpg)
OO ≡ ADT /
![Page 76: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/76.jpg)
William Cook, "On Understanding Data Abstraction, Revisited"
![Page 77: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/77.jpg)
public class RecentlyUsedList
{
...
public boolean equals(RecentlyUsedList other)
{
return other != null && items.equals(other.items);
}
public boolean equals(Object other)
{
return
other instanceof RecentlyUsedList &&
equals((RecentlyUsedList) other);
}
}
![Page 78: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/78.jpg)
bool equals(const RecentlyUsedList * lhs, const RecentlyUsedList * rhs)
{
return
lhs->length == rhs->length &&
memcmp(lhs->items, rhs->items, lhs->length * sizeof(int)) == 0;
}
![Page 79: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/79.jpg)
extern "C"
{
...
bool equals(const RecentlyUsedList * lhs, const RecentlyUsedList * rhs)
{
return lhs->items == rhs->items;
}
}
![Page 80: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/80.jpg)
bool equals(
const RecentlyUsedList * lhs, const RecentlyUsedList * rhs)
{
bool result = size(lhs) == size(rhs);
for(int index = 0; result && index != size(lhs); ++index)
result = get(lhs, index) == get(rhs, index);
return result;
}
![Page 81: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/81.jpg)
extern "C" bool equals(
const RecentlyUsedList * lhs, const RecentlyUsedList * rhs)
{
bool result = size(lhs) == size(rhs);
for(int index = 0; result && index != size(lhs); ++index)
result = get(lhs, index) == get(rhs, index);
return result;
}
![Page 82: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/82.jpg)
public class RecentlyUsedList
{
...
public boolean equals(RecentlyUsedList other)
{
boolean result = other != null && size() == other.size();
for(int index = 0; result && index != size(); ++index)
result = get(index).equals(other.get(index));
return result;
}
public boolean equals(Object other)
{
return
other instanceof RecentlyUsedList &&
equals((RecentlyUsedList) other);
}
}
![Page 83: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/83.jpg)
One of the most pure object-oriented
programming models yet defined is the
Component Object Model (COM). It
enforces all of these principles rigorously.
Programming in COM is very flexible and
powerful as a result. There is no built-in notion
of equality. There is no way to determine if
an object is an instance of a given class.
William Cook
"On Understanding Data Abstraction, Revisited"
![Page 84: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/84.jpg)
public class RecentlyUsedList
{
...
public boolean equals(RecentlyUsedList other)
{
boolean result = other != null && size() == other.size();
for(int index = 0; result && index != size(); ++index)
result = get(index).equals(other.get(index));
return result;
}
public boolean equals(Object other)
{
return
other instanceof RecentlyUsedList &&
equals((RecentlyUsedList) other);
}
}
![Page 85: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/85.jpg)
public class RecentlyUsedList
{
...
public boolean equals(RecentlyUsedList other)
{
boolean result = other != null && size() == other.size();
for(int index = 0; result && index != size(); ++index)
result = get(index).equals(other.get(index));
return result;
}
}
![Page 86: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/86.jpg)
In a purist view of object-oriented methodology, dynamic dispatch is the only mechanism for taking advantage of attributes that have been forgotten by subsumption. This position is often taken on abstraction grounds: no knowledge should be obtainable about objects except by invoking their methods. In the purist approach, subsumption provides a simple and effective mechanism for hiding private attributes.
![Page 87: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/87.jpg)
William Cook, "On Understanding Data Abstraction, Revisited"
![Page 88: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/88.jpg)
public interface RecentlyUsedList
{
boolean isEmpty();
int size();
void add(String toAdd);
String get(int index);
boolean equals(RecentlyUsedList other);
}
![Page 89: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/89.jpg)
public class RecentlyUsedListImpl
implements RecentlyUsedList
{
private List<String> items = …;
public boolean isEmpty() …
public int size() …
public void add(String toAdd) …
public String get(int index) …
public boolean equals(RecentlyUsedList other) …
public boolean equals(Object other) …
}
![Page 90: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/90.jpg)
public class ArrayListBasedRecentlyUsedList
implements RecentlyUsedList
{
private List<String> items = …;
public boolean isEmpty() …
public int size() …
public void add(String toAdd) …
public String get(int index) …
public boolean equals(RecentlyUsedList other) …
public boolean equals(Object other) …
}
![Page 91: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/91.jpg)
public class RandomAccessRecentlyUsedList
implements RecentlyUsedList
{
private List<String> items = …;
public boolean isEmpty() …
public int size() …
public void add(String toAdd) …
public String get(int index) …
public boolean equals(RecentlyUsedList other) …
public boolean equals(Object other) …
}
![Page 92: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/92.jpg)
RecentlyUsedList list =
new RandomAccessRecentlyUsedList();
![Page 93: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/93.jpg)
William Cook, "On Understanding Data Abstraction, Revisited"
![Page 94: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/94.jpg)
![Page 95: Object? You Keep Using that Word](https://reader034.fdocuments.in/reader034/viewer/2022042618/589eb2e81a28ab4a5c8b46c1/html5/thumbnails/95.jpg)