Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
Like Tree2Likes
  • 1 Post By Ronald Roe
  • 1 Post By TheGAME1264

Thread: Technical js

  1. #1
    Senior Member
    Join Date
    Apr 2016
    Posts
    717
    Member #
    53891
    Liked
    11 times

    Technical js

    So I'm making good progress with us, I have a good handle on sequencing branching looping arrays and all the crazy you can do with them and objects both literal and constructor but...

    Encapsulation
    Polymorphism
    Inheritance

    Can anyone help me get a better understanding of these they completely evade

  2.  

  3. #2
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    You're making me dig back into the early parts of my CompSci program.

    Encapsulation is a concept that is very heavily used and focused on in native OOP languages, like C++ and Java. Essentially, you don't want all of your variables to be accessible from outside objects. Best practice is that if you can avoid making a variable public, don't. It's better to protect the variable by making it private and provide methods inside the object to retrieve ("getter") or set ("setter") the variable's value.

    The concept is less prevalent in JavaScript, where most member variables are accessible by design. You can encapsulate variables inside an object by using the var, let or const keywords. This uses standard JS scoping rules, which makes them inaccessible outside the object. If you want to make your variables accessible as properties of the object (from outside it), you leave off the keywords and use the "this." notation. So,
    Code:
    var someObject = {
    this.someString = "Words and stuff"; //Accessible outside the object
    var someNum = 42; //Not accessible outside the object
    
    function getTheNum(){ //Getter method for the someNum variable
    return someNum;
    }
    }
    Last edited by Ronald Roe; Nov 03rd, 2016 at 06:02 PM.
    busso likes this.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  4. #3
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    Ron pretty much answered encapsulation, so I don't need to.

    Polymorphism is something that can be applied to multiple types of things. For example, a function that can be used on both a number and a string. It's commonly used in OOP languages/frameworks and has a great deal of use in languages/frameworks that utilize types as opposed to variants (for example, ASP.net as ASP.net utilizes types such as Int32 and String).

    Inheritance has two meanings that are somewhat similar to me.

    1) The CSS meaning, whereby elements inherit properties from their parents.
    2) The OOP meaning, whereby classes and objects inherit properties from other classes and objects. It's used quite a bit when you want to extend a class in ASP.net. For example, I'm writing a shopping cart whereby I created a class for common properties, subs, functions, etc based on ASP.net's Page class.

    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    I then use this class instead of the page class on the pages themselves to save time and avoid repeated variable declaration and assignment.
    busso likes this.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  5. #4
    Senior Member
    Join Date
    Apr 2016
    Posts
    717
    Member #
    53891
    Liked
    11 times
    so encapsulation is all about scope of a variable, polymorphism is essentially multi purpose functions and inheritence is, as i expected when an object inherits properties from another object or prototype?

  6. #5
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    Encapsulation is more about data and functions, and allowing programmers and users access to the data and functions on a "need to know" basis. Different people require and are entitled to different access.

    The rest sounds about right.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:53 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com