抽象意味着隐藏'实现细节'......那么抽象的目标是实现信息隐藏??如果不是实施细节,信息隐藏中隐藏了什么?抽象是一种如何隐藏信息的技术?
问问题
270 次
2 回答
0
抽象的目标不是隐藏变量值意义上的信息,这将是封装。
抽象的唯一目标是允许程序员在不理解算法或概念的情况下使用它。信息隐藏可能是这样做的副产品,但这不是它的目标。
于 2010-11-17T16:56:21.627 回答
0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/* Example of Abstratcion: An application for mobile manufacturing company - Every phone must have to implement caller
* and sms feature but it depends on company to company (or model to model) if they want to include other features or not
* which are readily available , you just have to use it without knowing its implementation (like facebook in this example).
*/
namespace AbstractTest
{
public abstract class feature
{
public abstract void Caller();
public abstract void SMS();
public void facebook()
{
Console.WriteLine("You are using facebook");
}
}
public class Iphone : feature
{
public override void Caller()
{
Console.WriteLine("iPhone caller feature");
}
public override void SMS()
{
Console.WriteLine("iPhone sms feature");
}
public void otherFeature()
{
facebook();
}
}
public class Nokia : feature
{
public override void Caller()
{
Console.WriteLine("Nokia caller feature");
}
public override void SMS()
{
Console.WriteLine("Nokia sms feature");
}
}
class Program
{
static void Main(string[] args)
{
Iphone c1 = new Iphone();
c1.Caller();
c1.SMS();
c1.otherFeature();
Nokia n1 = new Nokia();
n1.Caller();
n1.SMS();
Console.ReadLine();
}
}
}
于 2016-02-14T10:07:31.530 回答