950 likes | 2.4k Vues
Presented at Dynabyte (13th April 2016) <br><br>I do not think it means what you think it means. What object means to many programmers is managers, views, controllers, getters and setters, megalithic frameworks, spaghetti inheritance, lots of mocks and large classes. But is this what object-oriented development is really about? <br><br>The original vision of objects was focused more on the problem domain than the solution domain. Objects were supposed to be small, properly encapsulated abstractions composed from other objects. Classes were a mechanism for expressing objects, not the editing black hole of the development process. <br><br>Think you know objects? This talk strips back the layers of habits, frameworks and legacy to cast objects in a new but old light.
E N D
Object? You keep using that word... @KevlinHenney
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
hippopotomonstrosesquipedaliophobia pneumonoultramicroscopicsilicovolcanoconiosis fylkestrafikksikkerhetsutvalgssekretariatslederfunksjonene Rindfleischetikettierungsüberwachungsaufgabenübertragungsgesetz muvaffakiyetsizleştiricileştiriveremeyebileceklerimizdenmişsinizcesine
OBJECT OBJECT- -ORIENTED ORIENTED Door Door VenetianBlind VenetianBlind Television Television Glass Glass Picture Picture Peephole Peephole Sofa Sofa TelevisionRemoteControl TelevisionRemoteControl http://www.bonkersworld.net/object-world/
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.
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.
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 ...
public interface Book ... public final class ISBN ... public interface Catalogue ... public class DescriptionOfCatalogueImplementation implements Catalogue ...
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
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.
Member Loan BookCopy
IMember Loan IBookCopy Member BookCopy
Loan Member BookCopy
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
Borrower Loan LoanItem Member BookCopy
interface interface
Parser Builder Tree
Parser Builder Tree BuilderImpl
Parser ParserListener Tree Builder
Parser ParserListener Builder Tree
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.
Connection Factory Connection Connection Impl
Connection Pool Connection Pooled Connection
public Connection createConnection(Provider provider) throws ConnectionFailureException ...
public Connection connectTo(Provider ofUpdates) throws ConnectionFailure ...
OOP to me means only messaging, OOP to me means only messaging, local retention and protection and local retention and protection and hiding of state hiding of state- -process, and process, and extreme late extreme late- -binding of all binding of all things. It It can be done in Smalltalk and in can be done in Smalltalk and in LISP. There are possibly other LISP. There are possibly other systems in which this is possible, systems in which this is possible, but I'm not aware of them. but I'm not aware of them. things. Alan Kay Alan Kay
William Cook, "On Understanding Data Abstraction, Revisited" William Cook, "On Understanding Data Abstraction, Revisited"
Ignorance Ignorance Apathy Apathy Selfishness Selfishness
Identity Identity State State Behaviour Behaviour
Stack {push, pop, depth, top}
Stack[T] { push(T), pop(), depth() : Integer, top() : T }
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"
Stack[T] { push(T item), pop(), depth() : Integer, top() : T } given: before = depth() postcondition: depth() = before + 1 ∧ top() = item given: before = depth() precondition: before > 0 postcondition: depth() = before – 1 given: result = depth() postcondition: result ≥ 0 precondition: depth() > 0
alphabet(Stack) = {push, pop, depth, top}
trace(Stack) = {⟨⟩, ⟨push⟩, ⟨depth⟩, ⟨push, pop⟩, ⟨push, top⟩, ⟨push, depth⟩, ⟨push, push⟩, ⟨depth, push⟩, ⟨depth, depth⟩, ⟨push, push, pop⟩, ...}
push Empty Non-Empty pop [depth = 1] depth depth top push pop [depth > 1]
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() } }
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() } }
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() } }