Results 1 to 5 of 5

Thread: [RESOLVED] Class Property

  1. #1

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Resolved [RESOLVED] Class Property

    I'm a little confused to how one declares a property for a class in java and I'm not seeming to wrap my head around with the google searches either.

    Right now I have a class:
    Code:
    public abstract class LoanBaseClass {
        private double m_InterestAmount;
        private double m_MonthlyPayment;
        private double m_TotalLoan;
        private double m_LoanAmount;
        private int m_NumYears;
        
        public LoanBaseClass(){
            m_LoanAmount = 0.0;
            m_NumYears = 0;
        }
        public LoanBaseClass(double LoanAmount, int NumYears){
            m_LoanAmount = LoanAmount; //Need to use property instead
            m_NumYears = NumYears; //Need to use property instead
        }
        
        public abstract void CalcLoan();
        public abstract void CalcLoan(double LoanAmount, int NumYears);
    }
    And these variables I would like to make public properties:
    Code:
    private double m_InterestAmount;
        private double m_MonthlyPayment;
        private double m_TotalLoan;
        private double m_LoanAmount;
        private int m_NumYears;
    There is some validation in the SET part that I need to do.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  2. #2

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Class Property

    Heh, I knew Java was a little dated, I just didn't know it was in the stone age:
    Code:
        public double getInterest () {
            return m_InterestAmount;
        }
        
        public void setInterest (double Interest) {
            m_InterestAmount = Interest;
        }
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [RESOLVED] Class Property

    Well, I know properties are really cool in .Net but not an Object Oriented design patterns
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  4. #4

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: [RESOLVED] Class Property

    Quote Originally Posted by ComputerJy View Post
    Well, I know properties are really cool in .Net but not an Object Oriented design patterns
    Properties define what an object is, the lack of actual properties in Java means it's not as OO as it should be.

    I hear properties are slated to be added to Java 7.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  5. #5
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [RESOLVED] Class Property

    Quote Originally Posted by JuggaloBrotha
    I hear properties are slated to be added to Java 7.
    Yep.
    Quote Originally Posted by JuggaloBrotha
    Properties define what an object is, the lack of actual properties in Java means it's not as OO as it should be.
    No.
    Quote Originally Posted by Wikipedia
    Properties are read and written like fields, but property reads and writes are (usually) translated to get and set method calls. The field-like syntax is said to be easier to read and write than lots of method calls, yet the interposition of method calls allows for data validation, active updating (as of GUI visuals), and/or read-only 'fields'. That is, properties are intermediate between member code (methods) and member data (instance variables) of the class, and properties provide a higher level of encapsulation than public fields.
    What C# does is auto generate the getter and setter and package them in a nice block (the property). It's just to make your life easier not an OO essential
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

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