Investigation
Last updated
Was this helpful?
Last updated
Was this helpful?
The investigation concerns method naming and involves the names 'wrap' and 'wrapper' and already existing objects of the same name. Before starting an investigation, the and objects need to be brought closer for their minimal understanding.
The object represents the immutable text wrapped by the opening and closing chars, and it is designed to preserve the names of the opening, text, and closing.
As a noun - "material used for " - Merriam-Webster
As a noun - ", , or other that is used to something" - Cambridge Dictionary
The wrap is the thing that something is wrapped in. Something, in this case, is the text, and the thing is the opening and closing characters.
As a verb - "to put , , or other around something" - Cambridge Dictionary
Wrap something around another thing. Something, in this case, is the opening and closing characters, and the thing is the text.
The constructor of the object initializes by providing a required opening
, closing
, and optional text
to wrap. All the values are a part of the primitive value of this object and are stored separately in private values #opening
, #closing
, and #text
. Access to these properties is by get
accessors opening
, closing
and text
, so even the parts of the primitive value are immutable.
It can be understood as one or a machine that holds the wrap
to wrap any text by using it. One or a machine is just an object.
Wrapper's initialization.
The examples from previous pages explain how the methods can work on the instance, but the catch is in the wrap()
method used in two different objects. What does this method do?
Wrapper
objectThe wrap(text: string)
method of the Wrapper
object with the text
parameter uses the <
and >
of the Wrapper
instance to wrap the given text
.
Text
objectThe Text
object is extended by the String
, and its primitive value is given text. The wrap(opening: string, closing: string)
method of Text
with parameters opening
and closing
uses them to wrap the primitive value of the Text
instance.
The wrap word means the same in both Text
and Wrapper
objects - it wraps something.
The methods return the same result.
The methods have different parameters depending on the object.
The methods perform the wrap differently because they perform on different objects with different parameters, but it is still the same action of the 'wrap'.
The method wrap()
of the Text
instance wraps the text of a Text
instance with given opening
and closing
characters in the method.
The method wrap()
of the Wrapper
instance wraps the given method's text with the opening and closing characters of the Wrapper
instance.
There are two functionalities in the same method name.
There seems to be no sense to insight the method by a single attribute like consistent or intuitive because they are interdependent, and their meaning is different depending on perspectives. Let's do this because different perspectives should emerge during the read.
The method means the same in both `Text` and `Wrapper` objects because they perform the same 'wrap' action. It should be enough to indicate 'wrap' as an intuitive method name regardless of the object.
The method name is consistent because of encoded in generally known naming conventions.
However, when we look at the method as part of a specific object, it seems intuitive. If a method is of the Text
object, we intuitively know that we need to provide opening and closing parameters to the wrap()
method, and if it's of Wrapper
we know that we need to provide text.
If the object name is not ambiguous, its functionality too, intuitive usage of the wrap()
method is still possible because we can look at parameters to recognize what type of the wrap method it is.
The method is consistent because the result of its functionality of wrap does the same in both objects.
The method can be accused as inconsistent because it's called with different parameters depending on the object, which means their functionalities are divergent despite the same result.
However, when we look at the method as part of a specific object, it seems to be consistent. We consistently know that the method of the Text
object always has the same parameters, which are different from the Wrapper
object.
It is worth checking only the method name, not including the object and its functionality, because then it's possible to achieve constant intuitive method names, at first sight, indicating its meaning. The need is also to have the same parameters. They act similar to a function. Similar because methods pick the data from an instance.
There are two types of methods, first, changes the primitive value of a specified object with or without parameters, and second, uses the primitive value to change a given method's parameter.
There are two functionalities, and the object should not have both functionalities in one method cause of parameters conflict or even with additional parameters because of losing its simplicity. To achieve consistency and intuitiveness, we need to separate both functionalities using different method names, which can be wrap()
and wrapText()
of the exact meaning. It should be noted that the additional method increases the object's complexity.
Crucial is to have an intuitive naming. The wrap
refers that the text to be wrapped is in the instance. The wrapText
indicates that the text to be wrapped needs to be provided in the method parameter.
Let's analyze naming the methods to see it's not simple.
The is an extension of the object means it represents the immutable wrap of the opening and closing with the additional ability to use it to wrap text.
noun - "a of , , or other used to a " - Cambridge Dictionary
noun - "that in which something is " - Merriam-Webster
noun - "one that " - Merriam-Webster
The constructor of the object initializes by providing a required opening
, closing
, and optional text
to wrap.
Does the method name is ?
Does the method name is ?
Does the method is ?
The importance of interdependence forces to include at least and with .
The method is intuitive because its behaves cohesively and to the method name giving the same result, but can be accused as not intuitive because it's called with different parameters depending on the object, which means their functionalities are different despite the same result.
Does the method is ?