Archive for May, 2007|Monthly archive page

methods

instructions … distinct sequences of logic that an object can manipulate in order to perform its function, carry out its service, communicate with users and other program objects. methods can only have access to data known to their particular object, and provide a mechanism for accessing (for both reading and writing) the private data stored in an object or a class..

in programming code, methods consist of a sequence of statements required to perform an action, a set of input parameters to customize those actions, and possibly an output value (called return value) of some kind. constructors, accessors, static (i.e. class-level) methods, instance methods, and destructors all play a role in object programming.

source code: a walk-thru


//2: parameter declaration~specifies the information a method is given when it is executed

//3: method call~calls the method println (), which belongs to the object known as System.out, and which prints a line of text

//4: variable declaration~declares a variable called proverb, and assigns the string “Practise makes perfect!” to it

//5: method call~prints the string referred to by the variable proverb to the terminal window

//6: another method call~calls the method length() on the string object to determine how many characters the string contains


method declarations~a sequence of statements describing the actions the program and its objects must perform.

class declaration~a language construct to define a class; methods define classes by describing their actions

variables~named locations in the computer’s memory which hold values during program execution. methods often use variables told hold intermediate results. when we assign a value to a variable, we store the value in variable so that the value can get later referenced, via the variable.

naming conventions

classes ~ nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form
interfaces ~ capitalized like class names.
methods ~ verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.
constants ~ upper case letters and words separated by underscore
variables ~ mixed case with a lowercase first letter. Internal words start with capital letters. Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed. Variable names should be short yet meaningful. The choice of a variable name should be mnemonic- that is, designed to indicate to the casual observer the intent of its use. One-character variable names should be avoided except for temporary “throwaway” variables. Common names for temporary variables are i, j, k, m, and n for integers; c, d, and e for characters.

classes and encapsulation

Encapsulation refers to the design concept that each object carries its own data and provides a set of services that are involved in calling the objects methods. objects provide services by sending and receiving messages from other objects. encapsulation means users can access an object’s services and functionality, without having ready access to the object’s underlying data itself. encapsulation facilitates software design and development using a ‘block method’ as well as object reuse, information hiding, and control over each object’s ability to view other objects.

classes facilitate the encapsulation process, by defining object program logic and data fields. essentially, classes definitions describe the structure of executing objects ~ that is, they act as templates for the creation of new instances (known in the jargon as ‘instantiation’ ) of the class object. methods that exist at the object level, as opposed to the instance level, can access the data of all object instances in the class. methods that exist at the level of an object’s instance can only access that particular data. the goal of object-oriented programing becomes achieving a balance between the degree of linkages among the various classes of any program and the degree of consistency within each individual class.

object-oriented programming: a primer

a programming language model, object oriented programming focusses on “objects” rather than “actions” and data rather than logic. historically, programming has centred itself around a procedural focus: viewing a program as logical procedure that takes input data, processes it, and produces output data. and, then, viewing the programming challenge writing the logic, as opposed to defining the data.

object-oriented programming turns things on their side by turniing the emphasis of software and software programing from intense focus on logical procedures to intense focus on the programming objects we wish to manipulate with said logical procedures. so, programmers speak of attributes, methods and triggers, where previously they spoke of input/output and procedural logic.

for programmer, objects, their states, actions and the events (the word ‘trigger’ pops up here) that affects these states and actions become the focus of design and development. the notions of state and action seem intuitive enough that i will omit explaining them. however … what do we mean by “event” …. ?

the term “event(s)” specifically refers to events that affect system function, as opposed to those that describe a transaction that’s part of system function – i.e. ‘customer wanting to buy the merchandise’ describes the event, and not ‘customer provides his credit card’ — (its part of the purchase transaction, triggering by the initial purchase request). programmers work with temporal, state and external events.