[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.
Re: [RESOLVED] Class Property
Well, I know properties are really cool in .Net but not an Object Oriented design patterns
Re: [RESOLVED] Class Property
Quote:
Originally Posted by
ComputerJy
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.
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