Results 1 to 3 of 3

Thread: Object Oriented Programming Software Structures

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2015
    Posts
    1

    Object Oriented Programming Software Structures

    Hi,

    Forgive me for asking such a dumb question, also forgive me if I've posted in the wrong forum (I'm new here!), but I'm currently doing an assignment for college and I'm a little confused about classes and objects. After watching a video, I think I've got it about right, but I just want to ask just in case it's not. Is the following image the correct layout for an object oriented program, and have I used the correct terminology in the right place?

    Name:  oop.jpg
Views: 3084
Size:  24.7 KB

    Thanks in advance!

  2. #2
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,900

    Re: Object Oriented Programming Software Structures

    To be honest, I think you're way off. All the right terms are there but you seem to be miss-using them.

    Think of a class as a template. It's not an actual thing but it describes the common features of all instances of that thing. So if you have a class called Dog it's not a dog but it has place holders (attributes) for all the things you might need to record to describe a dog. It says that dogs have names, a breed, an owner and a current level of excitement. It also has methods which describe the things that all dogs do and how they do them. So it has a method called bark and wag tail. These methods will be shared by all instance (see below) of the class Dog.

    An object is an instance of a class. E.g. Spot. Spot's name is... well... Spot, his owner is Jason, his breed is cocker Spaniel and he's currently feeling a little frisky. So by assigning values to the various attributes of a Dog Class, we can describe Spot. And because Spot is an instance of Dog he can bark and wag his tail (because a Dogs methods are shared by all instances of Dog).

    Methods are the things we write in a class in order to describe how instances of that class should do things. So to bark a dog must open it's mouth, suck in some air, and then exhale it sharply to vibrate it's vocal chords. All dogs use the same basic mechanism for barking so we can write this method once, in the Dog class, and then all instances of Dog will bark in the same way.

    A function is a just type of method. It's a method that returns a value. So you might want to be able to tell how old a dog is. That would be a case of subtracting it's date of birth from todays date. So you'd write a method called Age which would do the maths and return the result. The corollary of functions are procedures. These are methods which don't return a value. So bark and wag tail would be procedures rather than functions.

    Public and Private are just to do with where a particular method or attribute can be accessed from. A private method or variable can only be called from the object it belongs to. So Bark and Wag Tail would probably be private methods - only Spot can decide whether he's excited enough to bark and wag his tail. Public methods and attributes are visible outside the object. So you might implement a method called Encourage which a dogs owner can call. The method would check if the dog was excited enough and, if so, would in turn call the private Bark and Wag Tail methods. Note that the owner can't wag Spot's tail or bark for him, but he can encourage Spot to bark and wag his own tail.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  3. #3
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,289

    Re: Object Oriented Programming Software Structures

    I would like to expand the knowledge about classes. Two things about classes. First is the object construction and second the meaning of internal variables in the class.
    Before the use of classes we deal with local and global variables as a matter of state. Programming is a matter of defining some series of states, and variables except for holding information also hold states, which means existence or not for specific physical stage in the flow of executing. So an object has to fit in that reality, holding state in a group of variables in own space, memory space. The construction phase is all about the first state, so we have by construction method to feed properly some variables. The concept of property are not a one to one analogy to state. We can say that all properties may define the state of object but maybe there is internal logic, hidden from programmer perspective that not allow the moving from one state to other. How can this done if we know all properties? Objects may have internal variables, not exposed to programmer to keep tracking the change of states.
    From programmer view object encapsulates logic not only offer a set of variables called properties and a set of functions called methods. A simple example is the document object of the documents collection in a Word.Application. Closing an empty document may or may not asked for saving and that depended from state before. There is a hidden Dirty flag that control the need for saving and that flag is not a property but exist inside.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width